package lib

import (
	"GameServer/Common/utils"
	"fmt"
	"math"
	"sort"

	"GameServer/Common/data"
	"GameServer/Game/errors"
	"GameServer/Game/m"

	log "github.com/sirupsen/logrus"
)

// 转动boss老虎机 获取时间
func BossSlotRotating(u *m.User, spin int64, gmKey int64) (slotKey int64, slotCard int64, err error) {
	rList, ok := data.GetAllDatas("BossSlotEvents")
	if !ok {
		err = errors.NewErrcode(data.Errcode.ConfigNotFound, "没有找到BossSlotEvents配置表")
		log.WithFields(log.Fields{
			"spin": spin,
		}).Error("BossSlotRotating")
		return
	}

	length := len(rList)
	weights := make([]data.WeightV, length)
	slotEvents := make([]data.BossSlotEvent, length)
	for i, item := range rList {
		itemT := item.(data.BossSlotEvent)
		randValue := uint64(0)
		for _, randvItem := range itemT.Randv {
			if int64(randvItem.Key) == spin {
				randValue = randvItem.Value
				break
			}
		}
		weights[i] = data.WeightV{Value: i, Weight: randValue}
		slotEvents[i] = itemT
	}

	weight := utils.RandomWeight(weights)
	index := utils.Int64(weight.Value)
	slotEvent := slotEvents[index].Event

	// 随机事件key
	length = len(slotEvent)
	weights = make([]data.WeightV, length)
	for i, item := range slotEvent {
		weights[i] = data.WeightV{Value: i, Weight: item.Key}
	}
	weight = utils.RandomWeight(weights)
	index = utils.Int64(weight.Value)
	event := slotEvent[index]

	slotKey = int64(event.Value) //事件
	if gmKey > 0 {               // gm指令
		slotKey = gmKey
	}

	// 获取事件中对应的卡片
	tpl, ok := data.Get("BossSlots", uint64(slotKey))
	if !ok {
		err = errors.NewErrcode(data.Errcode.ConfigNotFound, "没有找到BossSlots配置表")
		log.WithFields(log.Fields{
			"event.Value": event.Value,
		}).Error("BossSlotRotating")
		return
	}
	tplT := tpl.(data.BossSlot)

	// 随机卡片
	length = len(tplT.Randv)
	weights = make([]data.WeightV, length)
	for i, item := range tplT.Randv {
		weights[i] = data.WeightV{Value: i, Weight: item.Key}
	}
	weight = utils.RandomWeight(weights)
	index = utils.Int64(weight.Value)
	randv := tplT.Randv[index]

	slotCard = int64(randv.Value) //卡片id

	return
}

// 获取cardGmae中记录的BOSS.Tid世界BOSS血量
func GetMonsterHp_BSGame(cardGame *m.BSGame, bossTid int64) (hp int64) {
	u := &m.User{
		Uid: cardGame.Uid,
	}
	mcboss, _ := u.GetMCBoss(bossTid)
	hp = mcboss.Hp
	return
}

func PostHpHurtToWorldBoss_BSGame(cardGame *m.BSGame, totalHurt int64) {
	// 发送有效伤害给世界Boss
	if totalHurt > 0 {
		//*******用户uid，Boss tid，伤害totalHurt
		// var uid string = "temp" //用户uid
		var bossTid int64 = cardGame.Monster.Tid //boss的tid
		u := &m.User{}
		u.Uid = cardGame.Uid
		mcgroup, _ := u.GetMCGroup()
		mcgroup.CalcHurt(cardGame.Uid.Hex(), totalHurt, bossTid)
		// 玩家当前累伤
		gamer, ok := u.GetMCGamer()
		if !ok {
			fmt.Println("PostHpHurtToWorldBoss查找玩家失败")
			return
		}
		////////////////////////////////////////
		playerDmgAccu := gamer.MEachBossHurt[bossTid] //gamer.Hurt

		// 累计伤害
		// newDmgAccu := cardGame.DmgAccu + totalHurt
		// cardGame.UpdateDmgAccu(newDmgAccu)
		cardGame.UpdateDmgAccu(playerDmgAccu)
		// 得到累伤配置表
		tpl, ok := data.GetAllDatas("PlayerDmgAccuLevelLst")
		if ok {
			var dmgAccuLst []data.PlayerDmgAccuLevel
			for _, value := range tpl {
				theData := value.(data.PlayerDmgAccuLevel)
				dmgAccuLst = append(dmgAccuLst, theData)
			}
			var upPercent int64 = 0
			// var dmgLevel int64 = 0
			for _, configData := range dmgAccuLst {
				if playerDmgAccu >= int64(configData.Dmg) {
					if int64(configData.UpPercent) >= upPercent {
						upPercent = int64(configData.UpPercent)
						// dmgLevel = int64(configData.Level)
					}
				}
			}
			cardGame.AttBrustPercent = upPercent
			cardGame.Update(cardGame)
			// fmt.Printf("累计伤害%d,等级%d,增伤%d\n", playerDmgAccu, dmgLevel, upPercent)
		} else {
			// fmt.Print("累伤配置表 加载失败\n")
		}
	} else {
		// fmt.Print("有效伤害小于等于0，不上报伤害\n")
	}
}

// 生成新的卡牌游戏
func NewCardGame_BSGame(u *m.User, activID int64, monsterTid int64) (cardGame *m.BSGame, err error) {
	// 检查怪物是否在活动BOSS列表中
	// 获取历史数据
	cardGame = u.GetBSGame()
	// 检查怪物是否死亡
	serverBossHp := GetMonsterHp_BSGame(cardGame, monsterTid)
	if serverBossHp < 0 {
		err = errors.NewErrcode(data.Errcode.ServerErr, fmt.Sprintf("怪物已经死亡，tid:%d", cardGame.Monster.Tid))
		return
	}
	var NeedRest bool = false
	// 切换BOSS重置
	if cardGame.Monster == nil || cardGame.Monster.Tid != monsterTid {
		NeedRest = true
	}
	_, aConfig, _ := GetCurrentMulCombatConfig()
	EndTimeString := aConfig.EndTime
	EndTime, _ := utils.LayoutToTime(EndTimeString)
	cardGame.EndTime = EndTime.Unix() - 86400
	// fmt.Printf("玩家m层记录的上次世界BOSS活动ID = %d, 当前活动id = %d,round = %d \n", cardGame.LastActivId, activID, cardGame.Round)
	// 过期活动重置 -- cardGame.LastActivId != 0 是为了不影响当期的玩家
	// 这里不直接用cardGame.ActivId 判断，是因为8100 使用了GetBSGameByActId，会把activId进行设置,不过如果重置了，会把Round置位1，这里可以用来辅助判断
	if cardGame.LastActivId != activID && cardGame.Round == 1 {
		NeedRest = true
		// 只有活动不一致需要重置的内容
		cardGame.LastActivId = activID
		cardGame.DmgAccu = 0                                    //玩家累计伤害
		cardGame.DmgAccuBonusGain = make(map[int64]int64, 0)    //已领取累计伤害奖励
		cardGame.BossDefeatBonusGain = make(map[int64]int64, 0) //已领取BOSS击退奖励
		cardGame.PlayerShield = 0
	}
	// 怪物Tid不一致，活动不一致都会走这个重置分支
	if NeedRest {
		// 获取配置表信息
		tpl, ok := data.Get("CardMonsters", uint64(monsterTid))
		if !ok {
			err = errors.NewErrcode(data.Errcode.ConfigNotFound, fmt.Sprintf("没有找到怪物信息，tid:%d", monsterTid))
			return
		}
		monsterT := tpl.(data.CardMonster)
		if int64(monsterT.Type) != data.BSCardMonsterTypeEnum.WorldBoss {
			err = errors.NewErrcode(data.Errcode.ServerErr, fmt.Sprintf("怪物不是世界BOSS，tid:%d", monsterTid))
			return
		}
		// 给怪物赋值
		monster := &m.CardMonster{
			Tid:    monsterTid,
			Hp:     int64(monsterT.Hp),
			Skills: make(map[int64]*m.CardMonsterSkill, 0),
			Att:    int64(monsterT.Att),
		}
		cardGame.Monster = monster
		// 生成怪物技能
		for _, id := range monsterT.SkillIds {
			skillTpl, ok := data.Get("CardMonsterSkills", uint64(id))
			if !ok {
				err = errors.NewErrcode(data.Errcode.ConfigNotFound, fmt.Sprintf("没有找到怪物技能信息，tid:%d", id))
				return nil, err
			}
			skillT := skillTpl.(data.CardMonsterSkill)
			MonsterBuff_Add_BSGame(cardGame, skillT, 1, int64(skillT.StayRound))
		}

		bspTplLst, ok := data.GetAllDatas("BossSlotPlayers")
		if !ok {
			err = errors.NewErrcode(data.Errcode.ConfigNotFound, "没有找到BossSlotPlayers")
			return
		}
		sort.Slice(bspTplLst, func(i, j int) bool {
			a := bspTplLst[i].(data.BossSlotPlayer)
			b := bspTplLst[j].(data.BossSlotPlayer)
			return a.Id < b.Id
		})

		hp := bspTplLst[0].(data.BossSlotPlayer)     // 初始血条
		wager := bspTplLst[1].(data.BossSlotPlayer)  // 下注金币值
		energy := bspTplLst[2].(data.BossSlotPlayer) // 最大能量
		dmg := bspTplLst[3].(data.BossSlotPlayer)    // 攒满能量，增加伤害

		cardGame.MaxHP = int64(hp.Value) // 血量上限值
		cardGame.HP = int64(hp.Value)    // 当前血量值

		cardGame.Wager = int64(wager.Value) // 下注金币值

		cardGame.MaxEnergy = int64(energy.Value) // 最大能量值
		cardGame.Energy = 0                      // 当前能量值

		cardGame.DmgBonus = 0                // 当前伤害加成
		cardGame.DmgIncre = int64(dmg.Value) // 叠满能量，增加的伤害

		cardGame.Round = 1
		cardGame.CardBuffs = make([]*m.CardBuff, 0)
		cardGame.PlayerShield = 0

		realHp := GetMonsterHp_BSGame(cardGame, monsterTid)
		monster.Hp = realHp
		cardGame.Monster = monster
		cardGame.Status = 0

		cardGame.ShopBuyCnt = 0 // 神秘商店购买次数
		cardGame.ShopState = 0  // 神秘商店状态
	} else { // needRest = false
		realHp := GetMonsterHp_BSGame(cardGame, monsterTid)
		cardGame.Monster.Hp = realHp
		// 不需要重置（怪物没变，活动ID没变）的情况下
		// 如果玩家上次是死亡的(1)清空玩家的BUFF(2)重置费用(3)重置下回合卡牌减少(4)重置玩家护盾值
		if cardGame.Status > 0 {
			cardGame.CardBuffs = make([]*m.CardBuff, 0)
			cardGame.PlayerShield = 0
			cardGame.HP = cardGame.MaxHP
			cardGame.Energy = 0
			cardGame.DmgBonus = 0
		}
		cardGame.Status = 0
	}
	reflashBuffShow_Monster_BSGame(cardGame)

	cardGame.Update(cardGame)
	return
}

// 使用卡牌
func UseCard_BSGame(u *m.User, cardGame *m.BSGame, cardTid int64, PSend func(interface{}) error) (hattrs []*m.HurtAttr, err error) {
	// 获取使用卡牌
	tpl, ok := data.Get("BossSlotCards", uint64(cardTid))
	if !ok {
		err = errors.NewErrcode(data.Errcode.ConfigNotFound, fmt.Sprintf("没有找到用户卡牌配置信息，tid:%d", cardTid))
		return
	}
	cardConfig := tpl.(data.BossSlotCard)
	// 获得怪物信息
	monster := cardGame.Monster
	monsterTpl, ok := data.Get("CardMonsters", uint64(monster.Tid))
	if !ok {
		err = errors.NewErrcode(data.Errcode.ConfigNotFound, fmt.Sprintf("没有找到怪物配置信息，tid:%d", monster.Tid))
		return
	}
	monsterConfig := monsterTpl.(data.CardMonster) // 获得怪物配置表信息
	// 使用卡牌分类
	switch cardConfig.CardTyp {
	case uint64(data.BSCardTypeEnum.Atk): //攻击卡，立刻生效，不存buff,不叠加
		// 生成初始数据
		orgHurtLst := useCard_Atk_BSGame(cardGame, cardConfig, monsterConfig)
		// 对玩家护盾影响
		duelEffect_PlayerShield_BSGame(cardGame, orgHurtLst)
		// 对玩家血量增加
		duelEffect_PlayerHPAdd_BSGame(u, cardGame, orgHurtLst, PSend)
		// 对玩家法力水晶影响
		duelEffect_PlayerEnergy_BSGame(cardGame, orgHurtLst)
		// 装备卡加成，伤害修正--弱点/物竞天择/流血
		orgHurtLst = player_whenUseCard_BSGame(cardGame, orgHurtLst)
		// 受击技能修正(限抑制/伤害减免/护盾）-> 执行扣血 -> 血线伤害增幅 -> 反击(调用monster_whenAtk,player_whenHurt)
		orgHurtLst = monster_whenHurt_BSGame(cardGame, orgHurtLst, monsterConfig)
		hattrs = orgHurtLst
	case uint64(data.BSCardTypeEnum.Trap): //陷阱卡，陷阱阶段触发，存BUFF看CD，不叠加
		useCard_Trap_BSGame(cardGame, cardConfig)
	case uint64(data.BSCardTypeEnum.ContinuousTrap): //永续陷阱卡，陷阱阶段触发，常驻，叠加
		useCard_ContinuousTrap_BSGame(cardGame, cardConfig)
	case uint64(data.BSCardTypeEnum.Spell): //魔法卡，立刻触发，不存BUFF，不叠加
		orgHurtLst := useCard_Spell_BSGame(cardGame, cardConfig, monsterConfig)
		// 对玩家护盾影响
		duelEffect_PlayerShield_BSGame(cardGame, orgHurtLst)
		// 装备卡加成，伤害修正--弱点/物竞天择/流血
		orgHurtLst = player_whenUseCard_BSGame(cardGame, orgHurtLst)
		// 受击技能修正(限抑制/伤害减免/护盾）-> 执行扣血 -> 血线伤害增幅 -> 反击(调用monster_whenAtk,player_whenHurt)
		orgHurtLst = monster_whenHurt_BSGame(cardGame, orgHurtLst, monsterConfig)
		hattrs = orgHurtLst
	case uint64(data.BSCardTypeEnum.Equip): //装备卡，使用卡牌，陷阱阶段，怪物攻击时触发。存BUFF看CD，不叠加
		orgHurtLst := useCard_Equip_BSGame(cardGame, cardConfig, monsterConfig)
		// 对玩家护盾影响
		duelEffect_PlayerShield_BSGame(cardGame, orgHurtLst)
		// 装备卡加成，伤害修正--弱点/物竞天择/流血
		orgHurtLst = player_whenUseCard_BSGame(cardGame, orgHurtLst)
		// 对玩家血量增加
		duelEffect_PlayerHPAdd_BSGame(u, cardGame, orgHurtLst, PSend)
		// 受击技能修正(限抑制/伤害减免/护盾）-> 执行扣血 -> 血线伤害增幅 -> 反击(调用monster_whenAtk,player_whenHurt)
		orgHurtLst = monster_whenHurt_BSGame(cardGame, orgHurtLst, monsterConfig)
		hattrs = orgHurtLst
	}

	reflashBuffShow_Player_BSGame(cardGame)  // 刷新玩家buff的显示数值
	reflashBuffShow_Monster_BSGame(cardGame) // 刷新怪物buff的显示数值

	monsterhurtSum := int64(0)
	for _, hurtInfo := range hattrs {
		if int64(hurtInfo.Target) == data.BSCardEffectTargetEnum.Player &&
			int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.Hurt {
			monsterhurtSum += hurtInfo.Val
		}
	}

	cardGame.HP -= monsterhurtSum
	if cardGame.HP <= 0 && cardGame.Status == 0 { // 失败
		cardGame.Status = 2
	} else if cardGame.Monster.Hp <= 0 {
		cardGame.Status = 1
	}

	cardGame.Update(cardGame)
	return
}

// 回合结束
func RoundEnd_BSGame(cardGame *m.BSGame) (hattrs []*m.HurtAttr, err error) {
	monster := cardGame.Monster
	tpl, ok := data.Get("CardMonsters", uint64(monster.Tid))
	if !ok {
		err = errors.NewErrcode(data.Errcode.ConfigNotFound, fmt.Sprintf("没有找到怪物信息，tid:%d", monster.Tid))
		return
	}
	monsterT := tpl.(data.CardMonster)

	// 回合数加1
	cardGame.Round += 1
	defer cardGame.Update(cardGame)

	// 获取玩家陷阱伤害
	orgHurtLst := player_TrapAtk_BSGame(cardGame, int64(monsterT.Race))
	// 装备卡加成，伤害修正--物竞天择/流血
	orgHurtLst = player_whenUseCard_BSGame(cardGame, orgHurtLst)
	// 受击技能修正(限抑制/伤害减免/护盾）-> 执行扣血 -> 血线伤害增幅 -> 反击(调用monster_whenAtk,player_whenHurt)
	orgHurtLst = monster_whenHurt_BSGame(cardGame, orgHurtLst, monsterT)

	if monster.Hp > 0 {
		newHurtInfo := &m.HurtAttr{
			Tid:          int64(250100),
			Target:       data.BSCardEffectTargetEnum.Player,
			HurtType:     data.BSCardHurtTypeEnum.Hurt,
			Typ:          1,
			Val:          monster_GetRealAtt_BSGame(cardGame, monsterT),
			ShieldHurt:   0,
			CanBloodSuck: 1,
		}
		newHurtInfo.EffectBuff = make(map[int64]int64, 0)
		orgHurtLst = append(orgHurtLst, newHurtInfo)
		orgHurtLst = monster_whenAtk_BSGame(cardGame, orgHurtLst, monsterT)
	}

	orgHurtLst = monster_whenNewTurn_BSGame(cardGame, orgHurtLst, monsterT)

	hattrs = orgHurtLst

	monsterHurtSum := int64(0)
	for _, hurtInfo := range hattrs {
		if int64(hurtInfo.Target) == data.BSCardEffectTargetEnum.Player {
			if int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.Hurt {
				hurtNum := int64(hurtInfo.Val)
				if hurtNum > 0 {
					monsterHurtSum += hurtNum
				}
			}
		}
	}

	if monster.Hp <= 0 {
		cardGame.Status = 1
	} else {
		cardGame.HP -= monsterHurtSum
		if cardGame.HP <= 0 && cardGame.Status == 0 {
			cardGame.Status = 2 // 失败
		}
	}

	// 怪物Buff处理
	deleteBuffLst := make([]int64, 0)
	for _, skill := range monster.Skills {
		skillTpl, ok := data.Get("CardMonsterSkills", uint64(skill.Tid))
		if !ok {
			err = errors.NewErrcode(data.Errcode.ConfigNotFound, fmt.Sprintf("没有找到怪物技能信息，tid:%d", skill.Tid))
			return hattrs, err
		}
		skillT := skillTpl.(data.CardMonsterSkill)
		// 配表CD不为0，标识为需要计算CD的技能
		if skillT.Cd != 0 {
			if skill.Cd > 0 {
				skill.Cd = skill.Cd - 1
			} else {
				skill.Cd = int64(skillT.Cd) // 重新计算cd
			}
		}
		if skill.StayRound != 99 {
			skill.StayRound = skill.StayRound - 1
			if skill.StayRound < 0 {
				deleteBuffLst = append(deleteBuffLst, skill.Tid)
			}
		}
	}
	if len(deleteBuffLst) > 0 {
		for _, tid := range deleteBuffLst {
			delete(monster.Skills, tid)
		}
	}

	// 玩家buff 使用回合数减少
	for _, item := range cardGame.CardBuffs {
		if item.UseRound == 99 {
			continue
		}
		item.UseRound -= 1
	}
	// 清除无效buff
	cardBuffs := make([]*m.CardBuff, 0)
	for _, itemBuff := range cardGame.CardBuffs {
		if itemBuff.UseRound == 0 {
			continue
		}
		cardBuffs = append(cardBuffs, itemBuff)
	}

	reflashBuffShow_Player_BSGame(cardGame)  // 刷新玩家buff的显示数值
	reflashBuffShow_Monster_BSGame(cardGame) // 刷新怪物buff的显示数值

	monster.RoundHurt = 0
	cardGame.CardBuffs = cardBuffs

	return
}

// 领取卡牌怪物 奖励
func CardGameRewards_BSGame(from string, u *m.User, cardGame *m.BSGame, PSend func(interface{}) error) (uProp *m.UpdateProp, resGoods []*m.Goods, boxResList []*m.BoxRes, err error) {
	first := false //cardGame.IsFirstKillMonster(cardGame.Monster.Tid)
	tpl, ok := data.Get("CardMonsters", uint64(cardGame.Monster.Tid))
	if !ok {
		err = errors.NewErrcode(data.Errcode.ConfigNotFound, fmt.Sprintf("没有找到怪物信息，tid:%d", cardGame.Monster.Tid))
		return
	}
	defer cardGame.Update(cardGame)
	monsterT := tpl.(data.CardMonster)
	var resList []m.BaseKV
	if first { // 首杀奖励
		for _, item := range monsterT.Rewards1 {
			if utils.RandomInt64(1, 100) <= int64(item.Weight) {
				resList = append(resList, m.BaseKV{Key: utils.Int64(item.Key), Val: utils.Int64(item.Value)})
			}
		}
	} else {
		for _, item := range monsterT.Rewards2 {
			if utils.RandomInt64(1, 100) <= int64(item.Weight) {
				resList = append(resList, m.BaseKV{Key: utils.Int64(item.Key), Val: utils.Int64(item.Value)})
			}
		}
	}

	uProp, resGoods, boxResList, err = GiveGoodsByKvList(from, u, resList, PSend)
	if err != nil {
		return
	}
	cardGame.Status = 4
	// 领取奖励
	return
}

// 使用卡牌--攻击卡--给出初始数据，需要在外部修正处理（护盾之类的）
func useCard_Atk_BSGame(cardGame *m.BSGame, cardConfig data.BossSlotCard, monsterConfig data.CardMonster) (hattrs []*m.HurtAttr) {
	//----系统处理特殊逻辑，伤害枚举为99的攻击卡牌---
	UseSpecailAtkCard := func() {
		// 暂时没有伤害类型99的，需要特殊处理的，攻击卡牌
		return
	}
	//------------------End---------------------
	var monsterRace int64 = int64(monsterConfig.Race)
	var cardRaceTarget int64 = int64(cardConfig.HurtRace)
	// 多段伤害检查
	repit := utils.RandomInt64(int64(cardConfig.HurtRepetition.Min), int64(cardConfig.HurtRepetition.Max))
	// Mark:
	// 如果是单段伤害，repit，从[0,0]随机还是0.此时自增1，表现为1次伤害
	// 如果是多段伤害，直接取repit的值做循环，表现为repit次伤害
	repit = repit + 1
	for i := 0; i < int(repit); i++ {
		for _, hurtTypeValue := range cardConfig.HurtTyp {
			if int64(hurtTypeValue) == data.BSCardHurtTypeEnum.Custom {
				UseSpecailAtkCard() // 类型为99，服务器特殊处理，不走通用逻辑
				continue
			}
			for _, hurtInfo := range cardConfig.Hurt {
				if hurtInfo.HurtTyp == hurtTypeValue {
					orgHurt, hurtValueSupport, orgHurtInfoKey := getCardHurt_BSGame(hurtInfo, monsterRace, cardRaceTarget)
					newHurtObj := &m.HurtAttr{
						Tid:        int64(cardConfig.Id),     // 卡牌/技能ID
						Target:     int64(hurtInfo.Target),   // 作用对象
						HurtType:   int64(hurtInfo.HurtTyp),  // 伤害数值类型
						Typ:        orgHurtInfoKey,           // 伤害详细类型 1 固定伤害  2 连续伤害 3 额外伤害
						Val:        orgHurt,                  // 伤害数值
						ValSupport: hurtValueSupport,         // 辅助数值
						ShieldHurt: 0,                        // 对护盾伤害
						EffectBuff: make(map[int64]int64, 0), // key-buffId value-1-受此buff影响
						SpAtkTyp:   CombatSpAtkTypFormat(cardConfig.SpHurtTyp),
					}
					hattrs = append(hattrs, newHurtObj)
				}
			}
		}
	}
	return
}

// 使用卡牌--陷阱卡
func useCard_Trap_BSGame(cardGame *m.BSGame, cardConfig data.BossSlotCard) {
	// 回合结束触发，有回合数限制，不叠加
	cardGame.CardBuffs = append(cardGame.CardBuffs, &m.CardBuff{
		Tid:      int64(cardConfig.Id),
		CardType: int64(cardConfig.CardTyp),
		UseRound: int64(cardConfig.StatusTime),
		Val:      int64(cardConfig.StatusTime),
	})
}

// 使用卡牌--永续陷阱卡
func useCard_ContinuousTrap_BSGame(cardGame *m.BSGame, cardConfig data.BossSlotCard) {
	// 回合结束触发，可叠加，显示层数
	var hasBuff bool = false
	for _, buff := range cardGame.CardBuffs {
		if buff.Tid == int64(cardConfig.Id) {
			buff.Val = (buff.Val + 1)
			hasBuff = true
		}
	}
	if hasBuff == false {
		cardGame.CardBuffs = append(cardGame.CardBuffs, &m.CardBuff{
			Tid:      int64(cardConfig.Id),
			CardType: int64(cardConfig.CardTyp),
			UseRound: int64(cardConfig.StatusTime),
			Val:      1,
		})
	}
}

// 使用卡牌--魔法卡
func useCard_Spell_BSGame(cardGame *m.BSGame, cardConfig data.BossSlotCard, monsterConfig data.CardMonster) (hattrs []*m.HurtAttr) {
	// 立刻触发，不叠加，不存Buff
	// 法术充能，连锁陷阱
	var monsterRace int64 = int64(monsterConfig.Race)
	var cardRaceTarget int64 = int64(cardConfig.HurtRace)
	hattrs = make([]*m.HurtAttr, 0)
	switch cardConfig.Id {
	case 260001: // 法术充能
		orgHurt, hurtValueSupport, orgHurtInfoKey := getCardHurt_BSGame(cardConfig.Hurt[0], monsterRace, cardRaceTarget)
		newHurtObj := &m.HurtAttr{
			Tid:        int64(cardConfig.Id),                        // 卡牌/技能ID
			Target:     int64(data.BSCardEffectTargetEnum.Player),   // 作用对象
			HurtType:   int64(data.BSCardHurtTypeEnum.ManaIncrease), // 伤害数值类型
			Typ:        orgHurtInfoKey,                              // 伤害详细类型 1 固定伤害  2 连续伤害 3 额外伤害
			Val:        orgHurt,                                     // 伤害数值
			ValSupport: hurtValueSupport,                            // 辅助数值
			ShieldHurt: 0,                                           // 对护盾伤害
			EffectBuff: make(map[int64]int64, 0),                    // key-buffId value-1-受此buff影响
			SpAtkTyp:   CombatSpAtkTypFormat(cardConfig.SpHurtTyp),
		}
		hattrs = append(hattrs, newHurtObj)
	case 260016: // 连锁陷阱
		orgHurtLst := player_TrapAtk_BSGame(cardGame, monsterRace)
		for _, hurtInfo := range orgHurtLst {
			hattrs = append(hattrs, hurtInfo)
		}
	case 270016: // 连锁陷阱+
		orgHurtLst := player_TrapAtk_BSGame(cardGame, monsterRace)
		for _, hurtInfo := range orgHurtLst {
			hattrs = append(hattrs, hurtInfo)
		}
	default:
		if int64(cardConfig.CheckPoint) == data.BSCardMonsterSkillCheckPointEnum.WhenAtk ||
			int64(cardConfig.CheckPoint) == data.BSCardMonsterSkillCheckPointEnum.WhenCardDestroy {
			for _, hurtType := range cardConfig.HurtTyp {
				if cardConfig.Hurt != nil && len(cardConfig.Hurt) > 0 {
					for _, hurtInfo := range cardConfig.Hurt {
						if hurtInfo.HurtTyp == hurtType {
							orgHurt, hurtValueSupport, orgHurtInfoKey := getCardHurt_BSGame(hurtInfo, monsterRace, cardRaceTarget)
							newHurtObj := &m.HurtAttr{
								Tid:        int64(cardConfig.Id),     // 卡牌/技能ID
								Target:     int64(hurtInfo.Target),   // 作用对象
								HurtType:   int64(hurtInfo.HurtTyp),  // 伤害数值类型
								Typ:        orgHurtInfoKey,           // 伤害详细类型 1 固定伤害 2 连续伤害 3 额外伤害
								Val:        orgHurt,                  // 伤害数值
								ValSupport: hurtValueSupport,         // 辅助数值
								ShieldHurt: 0,                        // 对护盾伤害
								EffectBuff: make(map[int64]int64, 0), // key-buffId value-1 受此buff影响
								SpAtkTyp:   CombatSpAtkTypFormat(cardConfig.SpHurtTyp),
							}
							hattrs = append(hattrs, newHurtObj)
						}
					}
				}
			}
		}
	}
	return
}

// 使用卡牌--装备卡
func useCard_Equip_BSGame(cardGame *m.BSGame, cardConfig data.BossSlotCard, monsterConfig data.CardMonster) (hattrs []*m.HurtAttr) {
	// 使用卡牌，陷阱阶段，怪物攻击触发
	var monsterRace int64 = int64(monsterConfig.Race)
	var cardRaceTarget int64 = int64(cardConfig.HurtRace)
	hattrs = make([]*m.HurtAttr, 0)
	// -- buff叠加处理
	// 叠加buff，物竞天择，尖刺陷阱，流血，弱点,魔法屏障
	if cardConfig.StatusTime == 99 {
		// 叠加buff
		var hasBuff bool = false
		for _, buff := range cardGame.CardBuffs {
			if buff.Tid == int64(cardConfig.Id) {
				buff.Val = (buff.Val + 1)
				hasBuff = true
			}
		}
		if hasBuff == false {
			cardGame.CardBuffs = append(cardGame.CardBuffs, &m.CardBuff{
				Tid:      int64(cardConfig.Id),
				CardType: int64(cardConfig.CardTyp),
				UseRound: int64(cardConfig.StatusTime),
				Val:      1,
			})
		}
	} else {
		// 单独计数buff
		newCardBuff := &m.CardBuff{
			Tid:      int64(cardConfig.Id),
			CardType: int64(cardConfig.CardTyp),
			UseRound: int64(cardConfig.StatusTime),
			Val:      1, //int64(cardConfig.StatusTime),
		}
		// 流血
		if cardConfig.Id == 5001 || cardConfig.Id == 270020 {
			newCardBuff.Val = int64(cardConfig.Hurt[0].HurtInfo.Val1)
		}
		// 铁蒺藜
		if cardConfig.Id == 260029 || cardConfig.Id == 270029 {
			newCardBuff.Val = 1
		}
		// 物竞天择
		if cardConfig.Id == 260012 || cardConfig.Id == 270012 {
			newCardBuff.Val = 1
		}
		cardGame.CardBuffs = append(cardGame.CardBuffs, newCardBuff)
	}
	// -- 额外伤害处理
	for _, hurtType := range cardConfig.HurtTyp {
		isActiveHurtType := isHurtType_ActiveType_BSGame(int64(hurtType))
		if isActiveHurtType {
			// 多段伤害检查
			repit := utils.RandomInt64(int64(cardConfig.HurtRepetition.Min), int64(cardConfig.HurtRepetition.Max))
			repit = repit + 1
			for _, hurtInfo := range cardConfig.Hurt {
				if hurtInfo.HurtTyp == hurtType {
					orgHurt, hurtValueSupport, orgHurtInfoKey := getCardHurt_BSGame(hurtInfo, monsterRace, cardRaceTarget)
					newHurtObj := &m.HurtAttr{
						Tid:        int64(cardConfig.Id),     // 卡牌/技能ID
						Target:     int64(hurtInfo.Target),   // 作用对象
						HurtType:   int64(hurtInfo.HurtTyp),  // 伤害数值类型
						Typ:        orgHurtInfoKey,           // 伤害详细类型 1 固定伤害 2 连续伤害 3 额外伤害
						Val:        orgHurt,                  // 伤害数值
						ValSupport: hurtValueSupport,         // 辅助数值
						ShieldHurt: 0,                        // 对护盾伤害
						EffectBuff: make(map[int64]int64, 0), // key-buffId value-1 受此buff影响
						SpAtkTyp:   CombatSpAtkTypFormat(cardConfig.SpHurtTyp),
					}
					hattrs = append(hattrs, newHurtObj)
				}
			}
		}
	}
	return
}

// 卡牌伤害类型是否为主动类型
func isHurtType_ActiveType_BSGame(hurtType int64) (isActive bool) {
	isActive = false
	if hurtType == data.BSCardHurtTypeEnum.Hurt ||
		hurtType == data.BSCardHurtTypeEnum.Heal ||
		hurtType == data.BSCardHurtTypeEnum.CardIncrease ||
		hurtType == data.BSCardHurtTypeEnum.CardDecrease ||
		hurtType == data.BSCardHurtTypeEnum.ManaIncrease ||
		hurtType == data.BSCardHurtTypeEnum.ManaDecrease ||
		hurtType == data.BSCardHurtTypeEnum.RaceHurt ||
		hurtType == data.BSCardHurtTypeEnum.RaceHeal {
		isActive = true
	}
	return
}

// 游戏数据影响检测---玩家护盾
func duelEffect_PlayerShield_BSGame(cardGame *m.BSGame, orgHurtLst []*m.HurtAttr) {
	defer cardGame.Update(cardGame)
	for _, hurtInfo := range orgHurtLst {
		if int64(hurtInfo.Target) == data.BSCardEffectTargetEnum.Player {
			if int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.ShieldIncrease {
				// 玩家护盾增加 -- 可以在这里做上限抑制
				cardGame.PlayerShield = (cardGame.PlayerShield + hurtInfo.Val)
			} else if int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.ShieldDecrease {
				// 玩家护盾减少
				cardGame.PlayerShield = (cardGame.PlayerShield - hurtInfo.Val)
				if cardGame.PlayerShield < 0 {
					cardGame.PlayerShield = 0
				}
			}
		}
	}
}

// 游戏数据影响检测---法力水晶
func duelEffect_PlayerEnergy_BSGame(cardGame *m.BSGame, orgHurtLst []*m.HurtAttr) {
	for _, hurtInfo := range orgHurtLst {
		// 作用对象玩家，伤害类型 法力水晶增加
		if int64(hurtInfo.Target) == data.BSCardEffectTargetEnum.Player && int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.ManaCrystalIncrease {
			if cardGame.Spin > 1 {
				hurtInfo.Val *= cardGame.Spin //乘以倍率
			}
			cardGame.Energy += hurtInfo.Val
			// 法力水晶增加到最大值，增加累计伤害
			cardGame.DmgBonus += cardGame.Energy / cardGame.MaxEnergy * cardGame.DmgIncre
			cardGame.Energy %= cardGame.MaxEnergy
		}
	}
	cardGame.Update(cardGame)
}

// 游戏数据影响检测---玩家治疗
func duelEffect_PlayerHPAdd_BSGame(u *m.User, cardGame *m.BSGame, orgHurtLst []*m.HurtAttr, PSend func(interface{}) error) {
	for _, hurtInfo := range orgHurtLst {
		// 作用对象玩家，伤害类型回血
		if int64(hurtInfo.Target) == data.BSCardEffectTargetEnum.Player && int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.Heal {
			if cardGame.Spin > 1 {
				hurtInfo.Val *= cardGame.Spin //乘以倍率
			}
			cardGame.HP += hurtInfo.Val
		}
	}
	cardGame.Update(cardGame)
}

// 玩家，陷阱攻击
func player_TrapAtk_BSGame(cardGame *m.BSGame, monsterRace int64) (hattrs []*m.HurtAttr) {
	hattrs = make([]*m.HurtAttr, 0)
	for _, trap := range cardGame.CardBuffs {
		cardType := int64(trap.CardType)
		// 排除非陷阱/永续陷阱的卡
		if cardType != data.BSCardTypeEnum.Trap && cardType != data.BSCardTypeEnum.ContinuousTrap {
			continue
		}
		// 获取使用陷阱配置
		tpl, ok := data.Get("BossSlotCards", uint64(trap.Tid))
		if !ok {
			continue
		}
		cardConfig := tpl.(data.BossSlotCard)
		// 多段伤害
		repit := utils.RandomInt64(int64(cardConfig.HurtRepetition.Min), int64(cardConfig.HurtRepetition.Max))
		// Mark:
		// 如果是单段伤害，repit，从[0,0]随机还是0.此时自增1，表现为1次伤害
		// 如果是多段伤害，直接取repit的值做循环，表现为repit次伤害
		repit = repit + 1
		// 计算层级
		repit = repit * trap.Val
		//fmt.Printf("处理陷阱伤害 [%d] 攻击次数 %d \n", trap.Tid, repit)
		for i := 0; i < int(repit); i++ {
			for _, hurtTypeValue := range cardConfig.HurtTyp {
				if int64(hurtTypeValue) == data.BSCardHurtTypeEnum.Custom {
					//类型为99，服务器特殊处理，不走通用逻辑
					continue
				}
				for _, hurtInfo := range cardConfig.Hurt {
					if hurtInfo.HurtTyp == hurtTypeValue {
						orgHurt, hurtValueSupport, orgHurtInfoKey := getCardHurt_BSGame(hurtInfo, monsterRace, int64(cardConfig.HurtRace))
						newHurtObj := &m.HurtAttr{
							Tid:        int64(cardConfig.Id),     // 卡牌/技能ID
							Target:     int64(hurtInfo.Target),   // 作用对象
							HurtType:   int64(hurtInfo.HurtTyp),  // 伤害数值类型
							Typ:        orgHurtInfoKey,           // 伤害详细类型 1 固定伤害  2 连续伤害 3 额外伤害
							Val:        orgHurt,                  // 伤害数值
							ValSupport: hurtValueSupport,         // 辅助数值
							ShieldHurt: 0,                        // 对护盾伤害
							EffectBuff: make(map[int64]int64, 0), // key-buffId value-1-受此buff影响
							IsTrapVal:  1,                        // 0-普通伤害 1-陷阱伤害
							SpAtkTyp:   CombatSpAtkTypFormat(cardConfig.SpHurtTyp),
						}
						newHurtObj.EffectBuff = make(map[int64]int64, 0)
						newHurtObj.EffectBuff[int64(cardConfig.Id)] = 1
						hattrs = append(hattrs, newHurtObj)
					}
				}
			}
		}
	}
	return hattrs
}

// 当怪物进行攻击
func monster_whenAtk_BSGame(cardGame *m.BSGame, orgHurtLst []*m.HurtAttr, monsterConfig data.CardMonster) (hattrs []*m.HurtAttr) {
	defer cardGame.Update(cardGame)
	hattrs = orgHurtLst
	monster := cardGame.Monster                                        // 怪物
	var BloodSuckTid int64 = 0                                         // 吸血BuffTid
	var BloodSuckValue int64 = 0                                       // 吸血值
	var CoverSkill map[int64][]uint64 = make(map[int64][]uint64, 0)    // 取代类技能
	var AdditionSkill map[int64][]uint64 = make(map[int64][]uint64, 0) // 叠加类技能
	//后处理类技能
	var CriticalStrikeSkill map[int64][]uint64 = make(map[int64][]uint64, 0) // 暴击技能
	// 遍历生效时机为，攻击触发，的技能
	for _, skill := range monster.Skills {
		// cd 没到
		if skill.Cd != 0 {
			continue
		}
		// 获取技能配置表
		skillTpl, ok := data.Get("CardMonsterSkills", uint64(skill.Tid))
		if !ok { // 找不到技能配置
			continue
		}
		skillConfig := skillTpl.(data.CardMonsterSkill)
		if int64(skillConfig.CheckPoint) != data.BSCardMonsterSkillCheckPointEnum.WhenAtk {
			continue // checkPoint不是攻击生效
		}
		skillTyp := int64(skillConfig.SkillTyp)
		if skillTyp == data.BSCardMonsterSkillEnum.Attack_normal {
			continue // 普通攻击技能不处理
		}
		skillId := int64(skillConfig.Id)
		// 1普工
		switch skillTyp {
		case data.BSCardMonsterSkillEnum.Attack_recover: //5. 吸血
			BloodSuckValue = int64(skillConfig.Vals[0])
			BloodSuckTid = skillId
		//取代类技能
		case data.BSCardMonsterSkillEnum.Attack_time_dmgAccumulation: //2-多段攻击，攻击永久增幅
			CoverSkill[skillId] = skillConfig.Vals
		case data.BSCardMonsterSkillEnum.Attack_recover_dmgUp: //3-单次攻击，恢复血量，额外增伤
			CoverSkill[skillId] = skillConfig.Vals
		// 叠加类技能
		case data.BSCardMonsterSkillEnum.Attack_time: //4-多段攻击
			AdditionSkill[skillId] = skillConfig.Vals
		case data.BSCardMonsterSkillEnum.Steal_gold: //6-贪婪
			AdditionSkill[skillId] = skillConfig.Vals
		case data.BSCardMonsterSkillEnum.Mana_destroy: //7-法力摧毁
			AdditionSkill[skillId] = skillConfig.Vals
		case data.BSCardMonsterSkillEnum.Card_destroy: //8-卡牌破坏
			AdditionSkill[skillId] = skillConfig.Vals
		case data.BSCardMonsterSkillEnum.Buff_clear: // 22-净化清除玩家buff
			AdditionSkill[skillId] = skillConfig.Vals
		// 后处理类技能
		case data.BSCardMonsterSkillEnum.Attack_percent_dmgUp: // 18-概率暴击
			CriticalStrikeSkill[skillId] = skillConfig.Vals
		default:
		}
	}
	var normalAttCount int64 = 0

	for _, hurtInfo := range orgHurtLst {
		if int64(hurtInfo.Target) != data.BSCardEffectTargetEnum.Player {
			continue
		}
		if int64(hurtInfo.HurtType) != data.BSCardHurtTypeEnum.Hurt {
			continue
		}
		if int64(hurtInfo.Tid) == 250100 { // 非普通攻击
			normalAttCount = normalAttCount + 1
		}
	}
	if normalAttCount > 0 {
		// 处理取代类技能
		if CoverSkill != nil && len(CoverSkill) > 0 {
			newHurtAttr := make([]*m.HurtAttr, 0)
			// 屏蔽所有普通攻击
			for _, hurtInfo := range orgHurtLst {
				if int64(hurtInfo.Tid) != 250100 {
					newHurtAttr = append(newHurtAttr, hurtInfo)
				}
			}
			// 填入取代攻击数据
			for skillId, skillVals := range CoverSkill {
				skillTpl, ok := data.Get("CardMonsterSkills", uint64(skillId))
				if !ok { // 找不到技能配置
					//fmt.Println("取代攻击数据，找不到技能配置:", skillId)
					continue
				}
				skillConfig := skillTpl.(data.CardMonsterSkill)
				skillTyp := int64(skillConfig.SkillTyp)
				switch skillTyp {
				case data.BSCardMonsterSkillEnum.Attack_time_dmgAccumulation: //2-多段攻击，攻击永久增幅
					attBrustPercent := int64(skillVals[1])
					attAddTime := int(skillVals[0])
					for i := 0; i < attAddTime; i++ {
						monster.AttBrustPermanent = monster.AttBrustPermanent + attBrustPercent
						newHurt := &m.HurtAttr{
							Tid:      skillId,
							Target:   int64(data.BSCardEffectTargetEnum.Player),
							HurtType: int64(data.BSCardHurtTypeEnum.Hurt),
							Typ:      2,
							Val:      monster_GetRealAtt_BSGame(cardGame, monsterConfig),
						}
						newHurt.EffectBuff = make(map[int64]int64, 0)
						newHurt.EffectBuff[skillId] = 1
						newHurtAttr = append(newHurtAttr, newHurt)
					}
				case data.BSCardMonsterSkillEnum.Attack_recover_dmgUp: //3-单次攻击，恢复血量，额外增伤
					// 治疗
					var healNum int64 = int64(skillVals[0])
					newHeal := &m.HurtAttr{
						Tid:      skillId,
						Target:   int64(data.BSCardEffectTargetEnum.Monster),
						HurtType: int64(data.BSCardHurtTypeEnum.Heal),
						Typ:      1,
						Val:      healNum,
					}
					newHeal.EffectBuff = make(map[int64]int64, 0)
					newHeal.EffectBuff[skillId] = 1
					newHurtAttr = append(newHurtAttr, newHeal)
					// 伤害
					tempBrustAttPercent := int64(skillVals[1])
					newHurt := &m.HurtAttr{
						Tid:      skillId,
						Target:   int64(data.BSCardEffectTargetEnum.Player),
						HurtType: int64(data.BSCardHurtTypeEnum.Hurt),
						Typ:      1,
						Val:      monster_GetRealAttWithTempBrust_BSGame(cardGame, monsterConfig, tempBrustAttPercent),
					}
					newHurt.EffectBuff = make(map[int64]int64, 0)
					newHurt.EffectBuff[skillId] = 1
					newHurtAttr = append(newHurtAttr, newHurt)
				}
			}
			// 覆盖结果
			// orgHurtLst = newHurtAttr
			orgHurtLst = make([]*m.HurtAttr, 0)
			for _, hurtInfo := range newHurtAttr {
				orgHurtLst = append(orgHurtLst, hurtInfo)
			}
		}
		// 处理叠加类技能
		if AdditionSkill != nil && len(AdditionSkill) > 0 {
			// 直接在原攻击数据列表后追加攻击数据
			for skillId, skillVals := range AdditionSkill {
				skillTpl, ok := data.Get("CardMonsterSkills", uint64(skillId))
				if !ok { // 找不到技能配置
					//fmt.Println("取代攻击数据，找不到技能配置:", skillId)
					continue
				}
				skillConfig := skillTpl.(data.CardMonsterSkill)
				skillTyp := int64(skillConfig.SkillTyp)
				switch skillTyp {
				case data.BSCardMonsterSkillEnum.Steal_gold: //6-贪婪
					// stealPercent := int64(skillVals[0])
					// userGold, err := GetUserGold(cardGame.Uid.Hex())
					// if err != nil {
					// 	userGold = 0
					// }
					// hurtValue := int64(float64(userGold) * float64(stealPercent) / float64(100))
					// if hurtValue >= 10000000 {
					// 	hurtValue = 10000000
					// }
					// newHurt := &m.HurtAttr{
					// 	Tid:      skillId,
					// 	Target:   int64(data.BSCardEffectTargetEnum.Player),
					// 	HurtType: int64(data.BSCardHurtTypeEnum.Hurt),
					// 	Typ:      1,
					// 	Val:      hurtValue,
					// }
					// newHurt.EffectBuff = make(map[int64]int64, 0)
					// newHurt.EffectBuff[skillId] = 1
					// orgHurtLst = append(orgHurtLst, newHurt)
				case data.BSCardMonsterSkillEnum.Mana_destroy: //7-法力摧毁
					manaMinus := int64(skillVals[0])
					newHurt := &m.HurtAttr{
						Tid:      skillId,
						Target:   int64(data.BSCardEffectTargetEnum.Player),
						HurtType: int64(data.BSCardHurtTypeEnum.ManaDecrease),
						Typ:      1,
						Val:      manaMinus,
					}
					newHurt.EffectBuff = make(map[int64]int64, 0)
					newHurt.EffectBuff[skillId] = 1
					orgHurtLst = append(orgHurtLst, newHurt)
				case data.BSCardMonsterSkillEnum.Card_destroy: //8-卡牌破坏
					nextCardMinus := int64(skillVals[0])
					newHurt := &m.HurtAttr{
						Tid:      skillId,
						Target:   int64(data.BSCardEffectTargetEnum.Player),
						HurtType: int64(data.BSCardHurtTypeEnum.CardDecrease),
						Typ:      1,
						Val:      nextCardMinus,
					}
					newHurt.EffectBuff = make(map[int64]int64, 0)
					newHurt.EffectBuff[skillId] = 1
					orgHurtLst = append(orgHurtLst, newHurt)
				case data.BSCardMonsterSkillEnum.Attack_time: //4-多段攻击
					attAddTime := int(skillVals[0])
					for i := 0; i < attAddTime; i++ {
						newHurt := &m.HurtAttr{
							Tid:          skillId,
							Target:       int64(data.BSCardEffectTargetEnum.Player),
							HurtType:     int64(data.BSCardHurtTypeEnum.Hurt),
							Typ:          2,
							Val:          monster_GetRealAtt_BSGame(cardGame, monsterConfig),
							CanBloodSuck: 1,
						}
						newHurt.EffectBuff = make(map[int64]int64, 0)
						newHurt.EffectBuff[skillId] = 1
						orgHurtLst = append(orgHurtLst, newHurt)
					}
				case data.BSCardMonsterSkillEnum.Buff_clear: //22-净化
					clearBuffNum := int64(skillVals[0])
					var realClearBuffNum int64 = 0
					// 清理buff
					if len(cardGame.CardBuffs) > 0 && clearBuffNum > 0 {
						cardBuffs := make([]*m.CardBuff, 0)
						for _, itemBuff := range cardGame.CardBuffs {
							if clearBuffNum > 0 {
								clearBuffNum = clearBuffNum - 1
								realClearBuffNum = realClearBuffNum + 1
							} else {
								cardBuffs = append(cardBuffs, itemBuff)
							}
						}
						cardGame.CardBuffs = cardBuffs
					}
					// 添加攻击数据
					newHurt := &m.HurtAttr{
						Tid:      skillId,
						Target:   int64(data.BSCardEffectTargetEnum.Player),
						HurtType: int64(data.BSCardHurtTypeEnum.BuffDecrease),
						Typ:      1,
						Val:      realClearBuffNum,
					}
					newHurt.EffectBuff = make(map[int64]int64, 0)
					newHurt.EffectBuff[skillId] = 1
					orgHurtLst = append(orgHurtLst, newHurt)
				}
			}
		}
		// 后处理类技能
		// 暴击
		if CriticalStrikeSkill != nil && len(CriticalStrikeSkill) > 0 {
			for skillId, skillVals := range CriticalStrikeSkill {
				skillTpl, ok := data.Get("CardMonsterSkills", uint64(skillId))
				if !ok { // 找不到技能配置
					//fmt.Println("暴击，找不到技能配置:", skillId)
					continue
				}
				skillConfig := skillTpl.(data.CardMonsterSkill)
				skillTyp := int64(skillConfig.SkillTyp)
				switch skillTyp {
				case data.BSCardMonsterSkillEnum.Attack_percent_dmgUp: // 18-概率暴击
					criticalMark := int64(skillVals[0])
					finalCriticalPercent := int64(skillVals[1])
					for _, hurtInfo := range orgHurtLst {
						if int64(hurtInfo.Target) == data.BSCardEffectTargetEnum.Player {
							if int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.Hurt {
								if int64(hurtInfo.Val) > 0 { // 有效伤害
									if utils.RandomInt64(0, 100) <= criticalMark {
										theOrgHurt := hurtInfo.Val
										hurtInfo.Val = int64(float64(theOrgHurt) * float64(finalCriticalPercent) / float64(100))
										//fmt.Printf("怪物暴击，原伤害 %d ，最终伤害 %d \n", theOrgHurt, hurtInfo.Val)
										if hurtInfo.EffectBuff == nil {
											hurtInfo.EffectBuff = make(map[int64]int64, 0)
										}
										hurtInfo.EffectBuff[skillId] = 1
										hurtInfo.ValType = 2
									} else {
										//fmt.Printf("怪物没有触发暴击 伤害 %d", hurtInfo.Val)
									}
								}
							}
						}
					}
				default:
				}
			}
		}
	}
	// 处理吸血
	if BloodSuckValue > 0 {
		newHurtAttr := make([]*m.HurtAttr, 0)
		for _, hurtInfo := range orgHurtLst {
			newHurtAttr = append(newHurtAttr, hurtInfo)
			if int64(hurtInfo.Target) != data.BSCardEffectTargetEnum.Player {
				continue
			}
			if int64(hurtInfo.HurtType) != data.BSCardHurtTypeEnum.Hurt {
				continue
			}
			CanBloodSuck := int64(hurtInfo.CanBloodSuck)
			if CanBloodSuck == 1 {
				realHealNum := BloodSuckValue
				if (cardGame.Monster.Hp + realHealNum) >= int64(monsterConfig.Hp) {
					realHealNum = int64(monsterConfig.Hp) - cardGame.Monster.Hp
				}
				// 治疗
				newHeal := &m.HurtAttr{
					Tid:      BloodSuckTid,
					Target:   int64(data.BSCardEffectTargetEnum.Monster),
					HurtType: int64(data.BSCardHurtTypeEnum.Heal),
					Typ:      1,
					Val:      realHealNum,
				}
				newHeal.EffectBuff = make(map[int64]int64, 0)
				newHeal.EffectBuff[BloodSuckTid] = 1
				newHurtAttr = append(newHurtAttr, newHeal)
				// 实行吸血
				cardGame.Monster.Hp = (cardGame.Monster.Hp + realHealNum)
				if cardGame.Monster.Hp >= int64(monsterConfig.Hp) { // 回血上限
					cardGame.Monster.Hp = int64(monsterConfig.Hp)
				}
			}
		}
		// 覆盖
		orgHurtLst = make([]*m.HurtAttr, 0)
		for _, hurtInfo := range newHurtAttr {
			orgHurtLst = append(orgHurtLst, hurtInfo)
		}
	}
	hattrs = orgHurtLst
	hattrs = player_whenHurt_BSGame(cardGame, hattrs, monsterConfig) // 处理，玩家受到伤害
	return
}

// 预处理下回合开始
func monster_whenNewTurn_BSGame(cardGame *m.BSGame, orgHurtLst []*m.HurtAttr, monsterConfig data.CardMonster) (hattrs []*m.HurtAttr) {
	monster := cardGame.Monster // 怪物
	hattrs = orgHurtLst
	realHp := GetMonsterHp_BSGame(cardGame, monster.Tid)
	monster.Hp = realHp
	if monster.Hp < 0 {
		return
	}
	defer cardGame.Update(cardGame)
	for _, skill := range monster.Skills {
		// cd 没到
		if skill.Cd != 0 {
			continue
		}
		// 获取技能配置表
		skillTpl, ok := data.Get("CardMonsterSkills", uint64(skill.Tid))
		if !ok { // 找不到技能配置
			//fmt.Println("找不到技能配置", skill.Tid)
			continue
		}
		skillConfig := skillTpl.(data.CardMonsterSkill)
		skillTyp := int64(skillConfig.SkillTyp)
		skillId := int64(skillConfig.Id)
		if int64(skillConfig.CheckPoint) != data.BSCardMonsterSkillCheckPointEnum.WhenNewTurn {
			switch skillTyp {
			case data.BSCardMonsterSkillEnum.Hp_counter: // 反击
				skill.ExtVal = 0
				hurtLine := int64(skillConfig.Vals[0])
				leftNum := hurtLine - cardGame.Monster.HurtSum
				if leftNum <= 0 {
					leftNum = hurtLine
					cardGame.Monster.HurtSum = 0
				}
			case data.BSCardMonsterSkillEnum.Shield_fightBack: // 护盾反击
				skill.ExtVal = int64(skillConfig.Vals[1])
			}
			continue // checkPoint不是NewTurn
		}
		if skillTyp == data.BSCardMonsterSkillEnum.Attack_normal {
			continue // 普通攻击技能不处理
		}
		// 1普工
		switch skillTyp {
		case data.BSCardMonsterSkillEnum.Shild: //护盾
			monster.Shield = monster.Shield + int64(skillConfig.Vals[0]) // 护盾恢复
		case data.BSCardMonsterSkillEnum.Hp_decrease: // 自身毒性
			hurtNum := int64(skillConfig.Vals[0])
			newHurt := &m.HurtAttr{
				Tid:      skillId,
				Target:   int64(data.BSCardEffectTargetEnum.Monster),
				HurtType: int64(data.BSCardHurtTypeEnum.Hurt),
				Typ:      1,
				Val:      hurtNum,
			}
			newHurt.EffectBuff = make(map[int64]int64, 0)
			newHurt.EffectBuff[skillId] = 1
			orgHurtLst = append(orgHurtLst, newHurt)
			// 喂毒
			monster.Hp = monster.Hp - hurtNum
			if monster.Hp <= 0 {
				monster.Hp = 0
			}
		case data.BSCardMonsterSkillEnum.Injuried_recover: // 恢复损失血量
			recoverHp := int64((float64(monsterConfig.Hp) - float64(monster.Hp)) * float64(skillConfig.Vals[0]) / float64(100))
			if recoverHp > 0 {
				realHealNum := recoverHp
				if (cardGame.Monster.Hp + realHealNum) >= int64(monsterConfig.Hp) {
					realHealNum = int64(monsterConfig.Hp) - cardGame.Monster.Hp
				}
				// 治疗
				newHeal := &m.HurtAttr{
					Tid:      skillId,
					Target:   int64(data.BSCardEffectTargetEnum.Monster),
					HurtType: int64(data.BSCardHurtTypeEnum.Heal),
					Typ:      1,
					Val:      realHealNum,
				}
				newHeal.EffectBuff = make(map[int64]int64, 0)
				newHeal.EffectBuff[skillId] = 1
				orgHurtLst = append(orgHurtLst, newHeal)
				// 实行回血
				cardGame.Monster.Hp = (cardGame.Monster.Hp + realHealNum)
				if cardGame.Monster.Hp >= int64(monsterConfig.Hp) { // 回血上限
					cardGame.Monster.Hp = int64(monsterConfig.Hp)
				}
			}
		default:
		}
	}
	hattrs = orgHurtLst
	// fmt.Println("MonsterWhenNewTurn")
	return
}

// 当怪物收到伤害，执行扣血
func monster_whenHurt_BSGame(cardGame *m.BSGame, orgHurtLst []*m.HurtAttr, monsterConfig data.CardMonster) (hattrs []*m.HurtAttr) {
	hattrs = orgHurtLst
	realHp := GetMonsterHp_BSGame(cardGame, cardGame.Monster.Tid)
	cardGame.Monster.Hp = realHp
	if cardGame.Monster.Hp <= 0 {
		return
	}
	defer cardGame.Update(cardGame)
	monster := cardGame.Monster // 怪物

	var OverHitLimit_BuffId int64 = 0      // 上限抑制BuffId
	var OverHitLimit int64 = math.MaxInt64 // 上限抑制
	var HitMinus_block_BuffId int64 = 0
	var HitMinus_block int64 = 0 // 伤害减免-陷阱除外
	var HitMinus_blocking_BuffId int64 = 0
	var HitMinus_blocking int64 = 0                 // 伤害减免-所有
	var AtkBrustSkill map[int64]*data.KV            // 血线增伤
	var AtkBurstSkill_HpPointSub map[int64]*data.KV // 精准血量增伤
	var HpCounterSkill map[int64]*data.KV
	var DmgPercentBlockBuffId int64 = 0                  // 闪避BuffId
	var DmgPercentBlockMark int64 = 0                    // 闪避概率
	var Shield_FightBackMark map[int64]int64             // 护盾反击
	var SPatkPercentUpMark map[int64]int64               // 属性伤害倍数加成- key 属性枚举 - value 加成倍数单位%
	var SPatkPercentUpBuffId map[int64](map[int64]int64) // 属性伤害倍数加成 buffId集合- key 属性枚举(key-buffId - value -1)
	var SPatkPointUpMark map[int64]int64                 // 属性伤害点数加成- key 属性枚举 - value 加成点数
	var SPatkPointUpBuffId map[int64](map[int64]int64)   // 属性伤害点数加成 buffId集合- key 属性枚举(key-buffId - value -1)
	// 遍历生效时机为，受击触发，的技能
	for _, skill := range monster.Skills {
		// cd 没到
		if skill.Cd != 0 {
			continue
		}
		// 获取技能配置表
		skillTpl, ok := data.Get("CardMonsterSkills", uint64(skill.Tid))
		if !ok { // 找不到技能配置
			continue
		}
		skillConfig := skillTpl.(data.CardMonsterSkill)
		// 检测CheckPoint
		if int64(skillConfig.CheckPoint) != data.BSCardMonsterSkillCheckPointEnum.WhenHurt {
			continue // checkPoint不是受击生效
		}
		// 统计技能物料--(1)上限抑制ceiling(2)伤害减免block,blocking
		skillTyp := int64(skillConfig.SkillTyp)
		if skillTyp == data.BSCardMonsterSkillEnum.Attack_normal {
			continue // 普通攻击不处理
		}
		skillId := int64(skillConfig.Id)
		// 处理上限抑制类技能，ceiling
		if skillTyp == data.BSCardMonsterSkillEnum.Ceiling {
			if int64(skillConfig.Vals[0]) < OverHitLimit {
				OverHitLimit = int64(skillConfig.Vals[0])
				OverHitLimit_BuffId = skillId
			}
		}
		// 伤害减免类，block(陷阱除外，自身毒性除外)
		if skillTyp == data.BSCardMonsterSkillEnum.Block {
			HitMinus_block = (HitMinus_block + int64(skillConfig.Vals[0]))
			HitMinus_block_BuffId = skillId
		}
		// 伤害减免类，blocking（自身毒性除外）
		if skillTyp == data.BSCardMonsterSkillEnum.Blocking {
			HitMinus_blocking = (HitMinus_blocking + int64(skillConfig.Vals[0]))
			HitMinus_blocking_BuffId = skillId
		}
		// 伤害增幅类，血线增幅，Hp_sub_dmgAccumulation
		if skillTyp == data.BSCardMonsterSkillEnum.Hp_sub_dmgAccumulation {
			if AtkBrustSkill == nil {
				AtkBrustSkill = make(map[int64]*data.KV, 0)
			}
			AtkBrustSkill[skillId] = &data.KV{
				Key:   uint64(skillConfig.Vals[0]),
				Value: uint64(skillConfig.Vals[1]),
			}
		}
		// 精准血量增伤
		if skillTyp == data.BSCardMonsterSkillEnum.Hp_subPoint_dmgAccumulation {
			if AtkBurstSkill_HpPointSub == nil {
				AtkBurstSkill_HpPointSub = make(map[int64]*data.KV, 0)
			}
			AtkBurstSkill_HpPointSub[skillId] = &data.KV{
				Key:   uint64(skillConfig.Vals[0]),
				Value: uint64(skillConfig.Vals[1]),
			}
		}
		// 反击
		if skillTyp == data.BSCardMonsterSkillEnum.Hp_counter {
			if skill.ExtVal >= 0 { //触发反击，会设置为-1，回合开始会重置
				if HpCounterSkill == nil {
					HpCounterSkill = make(map[int64]*data.KV, 0)
				}
				HpCounterSkill[skillId] = &data.KV{
					Key:   uint64(skillConfig.Vals[0]),
					Value: uint64(skillConfig.Vals[1]),
				}
			}
		}
		// 闪避
		if skillTyp == data.BSCardMonsterSkillEnum.Dmg_percent_block {
			DmgPercentBlockBuffId = skillId
			DmgPercentBlockMark = int64(skillConfig.Vals[0])
		}
		// 护盾反击
		if skillTyp == data.BSCardMonsterSkillEnum.Shield_fightBack {
			if skill.ExtVal > 0 {
				if Shield_FightBackMark == nil {
					Shield_FightBackMark = make(map[int64]int64, 0)
				}
				Shield_FightBackMark[skillId] = int64(skillConfig.Vals[0])
				skill.ExtVal = skill.ExtVal - 1
				if skill.ExtVal <= 0 {
					skill.ExtVal = 0
				}
			}
		}
		// 属性伤害倍数加成 - key 属性枚举 - value 加成倍数单位%
		if skillTyp == data.BSCardMonsterSkillEnum.BeSpAtk_hurtPercentUp {
			if SPatkPercentUpMark == nil {
				SPatkPercentUpMark = make(map[int64]int64, 0)
			}
			if SPatkPercentUpBuffId == nil {
				SPatkPercentUpBuffId = make(map[int64]map[int64]int64, 0)
			}
			// 数值记录
			spTyp := int64(skillConfig.Vals[0])           // 属性
			val := int64(skillConfig.Vals[1]) * skill.Val // 加成值 * 层数
			orgNum := int64(0)                            // 原始值
			_, find := SPatkPercentUpMark[spTyp]
			if find {
				orgNum = SPatkPercentUpMark[spTyp]
			}
			SPatkPercentUpMark[spTyp] = orgNum + val
			// 引用记录
			_, find = SPatkPercentUpBuffId[spTyp]
			if find == false || SPatkPercentUpBuffId[spTyp] == nil {
				SPatkPercentUpBuffId[spTyp] = make(map[int64]int64, 0)
			}
			SPatkPercentUpBuffId[spTyp][skillId] = 1
		}
		// 属性伤害点数加成 - key 属性枚举 - value 加成点数
		if skillTyp == data.BSCardMonsterSkillEnum.BeSpAtk_hurtPointUp {
			if SPatkPointUpMark == nil {
				SPatkPointUpMark = make(map[int64]int64, 0)
			}
			if SPatkPointUpBuffId == nil {
				SPatkPointUpBuffId = make(map[int64]map[int64]int64, 0)
			}
			// 数值记录
			spTyp := int64(skillConfig.Vals[0])           // 属性
			val := int64(skillConfig.Vals[1]) * skill.Val // 加成值 * 层数
			orgNum := int64(0)                            // 原始值
			_, find := SPatkPointUpMark[spTyp]
			if find {
				orgNum = SPatkPointUpMark[spTyp]
			}
			SPatkPointUpMark[spTyp] = orgNum + val
			// 引用记录
			_, find = SPatkPointUpBuffId[spTyp]
			if find == false || SPatkPointUpBuffId[spTyp] == nil {
				SPatkPointUpBuffId[spTyp] = make(map[int64]int64, 0)
			}
			SPatkPointUpBuffId[spTyp][skillId] = 1
		}
	}
	// 处理伤害列表--(1)上限抑制ceiling(2)伤害减免block,blocking(3)护盾
	var CounterHurtArr []*m.HurtAttr
	for _, hurtInfo := range orgHurtLst {
		if int64(hurtInfo.Target) != data.BSCardEffectTargetEnum.Monster {
			continue
		}

		if int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.Hurt ||
			int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.RaceHurt ||
			int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.FightBack {
			// 处理，属性攻击加成
			if int64(hurtInfo.Val) > 0 && hurtInfo.SpAtkTyp != nil && len(hurtInfo.SpAtkTyp) > 0 {
				// 点数加成
				if SPatkPointUpMark != nil && len(SPatkPointUpMark) > 0 {
					for spTyp, _ := range hurtInfo.SpAtkTyp {
						_, find := SPatkPointUpMark[spTyp]
						if find {
							pointUp := SPatkPointUpMark[spTyp] // 追加伤害
							// 可正/负，0就不处理了
							if pointUp != 0 {
								hurtInfo.Val = hurtInfo.Val + pointUp
								// 填入受影响的buff表中
								if hurtInfo.EffectBuff == nil {
									hurtInfo.EffectBuff = make(map[int64]int64, 0)
								}
								_, find = SPatkPointUpBuffId[spTyp]
								if find && SPatkPointUpBuffId[spTyp] != nil && len(SPatkPointUpBuffId) > 0 {
									for buffId, _ := range SPatkPointUpBuffId[spTyp] {
										hurtInfo.EffectBuff[buffId] = 1
									}
								}
							}
						}
					}
				}
				// 倍数加成
				if SPatkPercentUpMark != nil && len(SPatkPercentUpMark) > 0 {
					for spTyp, _ := range hurtInfo.SpAtkTyp {
						_, find := SPatkPercentUpMark[spTyp]
						if find {
							percentUp := SPatkPercentUpMark[spTyp] // 追加倍数
							if percentUp > 0 {
								orgHurt := hurtInfo.Val
								finalVal := orgHurt + int64(float64(orgHurt)*float64(percentUp)/float64(100))
								hurtInfo.Val = finalVal
								// 填入受影响的buff表中
								if hurtInfo.EffectBuff == nil {
									hurtInfo.EffectBuff = make(map[int64]int64, 0)
								}
								_, find = SPatkPercentUpBuffId[spTyp]
								if find && SPatkPercentUpBuffId[spTyp] != nil && len(SPatkPercentUpBuffId) > 0 {
									for buffId, _ := range SPatkPercentUpBuffId[spTyp] {
										hurtInfo.EffectBuff[buffId] = 1
									}
								}
							}
						}
					}
				}
			}
			//处理上限抑制 OverHitLimit
			if int64(hurtInfo.Val) > OverHitLimit {
				hurtInfo.Val = OverHitLimit
				if hurtInfo.EffectBuff == nil {
					hurtInfo.EffectBuff = make(map[int64]int64, 0)
				}
				hurtInfo.EffectBuff[OverHitLimit_BuffId] = 1
			}
			// 处理护盾反伤数据
			if Shield_FightBackMark != nil && len(Shield_FightBackMark) > 0 && cardGame.Monster.Shield > 0 && hurtInfo.CanFightBack == 0 {
				for skillId, hurtVal := range Shield_FightBackMark {
					monsterShieldCounter := &m.HurtAttr{
						Tid:          skillId,
						Target:       int64(data.BSCardEffectTargetEnum.Player),
						HurtType:     int64(data.BSCardHurtTypeEnum.Hurt),
						Typ:          1,
						Val:          hurtVal,
						ShieldHurt:   0,
						CanBloodSuck: 1, // 允许吸血
						CanFightBack: 1, // 0-支持反击 1-不支持反击
					}
					monsterShieldCounter.EffectBuff = make(map[int64]int64, 0)
					monsterShieldCounter.EffectBuff[skillId] = 1
					if CounterHurtArr == nil {
						CounterHurtArr = make([]*m.HurtAttr, 0)
					}
					CounterHurtArr = append(CounterHurtArr, monsterShieldCounter)
				}
			}
			// 闪避
			if DmgPercentBlockBuffId > 0 && DmgPercentBlockMark > 0 && hurtInfo.Val > 0 {
				if utils.RandomInt64(0, 100) < DmgPercentBlockMark {
					hurtInfo.Val = 0
					if hurtInfo.EffectBuff == nil {
						hurtInfo.EffectBuff = make(map[int64]int64, 0)
					}
					hurtInfo.EffectBuff[DmgPercentBlockBuffId] = 1
					hurtInfo.ValType = 1
					//fmt.Printf("怪物闪避了攻击[%d]", hurtInfo.Tid)
				}
			}
			// 伤害减免类，block（陷阱除外，自身毒性除外）处理
			if HitMinus_block > 0 && hurtInfo.Val > 0 {
				// 获取使用卡牌
				if hurtInfo.Tid == 260013 || hurtInfo.Tid == 260015 || hurtInfo.Tid == 260016 || hurtInfo.Tid == 260014 {
					// 陷阱除外
					// 260013-毒蛇陷阱
					// 260015-滚石陷阱
					// 260016-连锁陷阱
					// 260014-尖刺陷阱
				} else {
					hurtInfo.Val = (hurtInfo.Val - HitMinus_block)
					if hurtInfo.Val <= 0 {
						hurtInfo.Val = 0
					}
					if hurtInfo.EffectBuff == nil {
						hurtInfo.EffectBuff = make(map[int64]int64, 0)
					}
					hurtInfo.EffectBuff[HitMinus_block_BuffId] = 1
				}
			}
			// 伤害减免类，blocking（自身毒性除外）处理
			if HitMinus_blocking > 0 && hurtInfo.Val > 0 {
				hurtInfo.Val = (hurtInfo.Val - HitMinus_blocking)
				if hurtInfo.Val <= 0 {
					hurtInfo.Val = 0
				}
				if hurtInfo.EffectBuff == nil {
					hurtInfo.EffectBuff = make(map[int64]int64, 0)
				}
				hurtInfo.EffectBuff[HitMinus_blocking_BuffId] = 1
			}
			// 护盾处理
			if cardGame.Monster.Shield > 0 && hurtInfo.Val > 0 {
				var hurtNum int64 = int64(hurtInfo.Val)
				if hurtNum <= cardGame.Monster.Shield {
					hurtInfo.Val = 0
					cardGame.Monster.Shield = (cardGame.Monster.Shield - hurtNum)
					if cardGame.Monster.Shield <= 0 {
						cardGame.Monster.Shield = 0
					}
					hurtInfo.ShieldHurt = hurtNum
					if hurtInfo.EffectBuff == nil {
						hurtInfo.EffectBuff = make(map[int64]int64, 0)
					}
					hurtInfo.EffectBuff[250401] = 1
				} else {
					shieldHurt := cardGame.Monster.Shield
					hurtInfo.Val = hurtNum - shieldHurt
					cardGame.Monster.Shield = 0
					hurtInfo.ShieldHurt = shieldHurt
					if hurtInfo.EffectBuff == nil {
						hurtInfo.EffectBuff = make(map[int64]int64, 0)
					}
					hurtInfo.EffectBuff[250401] = 1
				}
			}
		}
	}
	// 伤害修正结束，实现伤害
	curTurnRealHurt := int64(0)
	for _, hurtInfo := range orgHurtLst {
		if int64(hurtInfo.Val) <= 0 {
			continue
		}
		if int64(hurtInfo.Target) != data.BSCardEffectTargetEnum.Monster {
			continue
		}
		var hurtTypeInt64 int64 = int64(hurtInfo.HurtType)
		if hurtTypeInt64 == data.BSCardHurtTypeEnum.Hurt ||
			hurtTypeInt64 == data.BSCardHurtTypeEnum.RaceHurt ||
			hurtTypeInt64 == data.BSCardHurtTypeEnum.FightBack {
			if cardGame.Monster.Hp <= 0 {
				cardGame.Monster.Hp = 0
				break
			} else {
				var hurtNum int64 = int64(hurtInfo.Val)
				cardGame.Monster.HurtSum = (cardGame.Monster.HurtSum + hurtNum) // 累计受到伤害
				cardGame.Monster.Hp = (cardGame.Monster.Hp - hurtNum)
				curTurnRealHurt = curTurnRealHurt + hurtNum // 溢出的伤害也计算
				if cardGame.Monster.Hp <= 0 {
					cardGame.Monster.Hp = 0
					break
				}
			}
		}
		// 对盾牌特殊伤害
		if hurtTypeInt64 == data.BSCardHurtTypeEnum.ShieldDecrease {
			if cardGame.Monster.Shield > 0 {
				var shieldHurtVal int64 = hurtInfo.Val
				var monsterOrgShield int64 = cardGame.Monster.Shield
				cardGame.Monster.Shield = cardGame.Monster.Shield - hurtInfo.Val
				if cardGame.Monster.Shield <= 0 {
					// 盾牌扣完，意味着伤害溢出，或刚好
					cardGame.Monster.Shield = 0
					hurtInfo.Val = 0
					hurtInfo.ShieldHurt = monsterOrgShield
				} else {
					// 盾牌没扣完，伤害为卡牌定义伤害
					hurtInfo.Val = 0
					hurtInfo.ShieldHurt = shieldHurtVal
				}
			} else {
				// 怪物此时没有护盾，不会造成伤害
				hurtInfo.Val = 0
				hurtInfo.ShieldHurt = 0
			}
		}
		// 赋予怪物buff
		if hurtTypeInt64 == data.BSCardHurtTypeEnum.BuffIncrease {
			addBuffTid := hurtInfo.Val        // 增加BUFF的Tid
			addBuffVal := hurtInfo.ValSupport // 增加BUFF的层数
			// 获取技能配置表
			skillTpl, ok := data.Get("CardMonsterSkills", uint64(addBuffTid))
			if ok {
				skillConfig := skillTpl.(data.CardMonsterSkill)
				if skillConfig.StayRound == 99 {
					// 永久技能，对应的是层数
					MonsterBuff_Add_BSGame(cardGame, skillConfig, addBuffVal, int64(skillConfig.StayRound))
				} else {
					// 短暂技能，对应的是回合数
					MonsterBuff_Add_BSGame(cardGame, skillConfig, 1, addBuffVal)
				}
			}
		}
	}
	hattrs = orgHurtLst
	PostHpHurtToWorldBoss_BSGame(cardGame, curTurnRealHurt) // 通知世界BOSS，受伤
	// 判死，如果死亡，不会进行反击和增幅
	if cardGame.Monster.Hp <= 0 {
		return
	}
	// 血线增伤
	if AtkBrustSkill != nil && len(AtkBrustSkill) > 0 {
		cardGame.Monster.Att = int64(monsterConfig.Att)
		cardGame.Monster.AttBrustPermanent = 0 // 重置永久增伤百分比
		LoseHpPercent := int64((float64(monsterConfig.Hp) - float64(cardGame.Monster.Hp)) / float64(monsterConfig.Hp) * float64(100))
		for _, BrustInfo := range AtkBrustSkill {
			brustThreshold := int64(BrustInfo.Key) // 触发增幅的阈值
			brustPercent := int64(BrustInfo.Value) // 触发增幅的百分数
			if LoseHpPercent >= brustThreshold {
				brustTime := LoseHpPercent / brustThreshold
				finalBrustPercent := float64(brustTime) * float64(brustPercent)
				if finalBrustPercent > 0 {
					cardGame.Monster.AttBrustPermanent = (cardGame.Monster.AttBrustPermanent + int64(finalBrustPercent))
				}
			}
		}
	}
	// 精准血量增伤
	if AtkBurstSkill_HpPointSub != nil && len(AtkBurstSkill_HpPointSub) > 0 {
		for _, skill := range AtkBurstSkill_HpPointSub {
			brustThreshold := int64(skill.Key) // 精准血量增伤阈值
			brustPercent := int64(skill.Value) // 增伤百分比
			if cardGame.Monster.HurtSum >= brustThreshold {
				cardGame.Monster.HurtSum = 0 // 精准血量增伤，和反击公用一个伤害缓存，如果触发了此技能，反击将不会触发
				cardGame.Monster.AttBrustHpPoint = (cardGame.Monster.AttBrustHpPoint + brustPercent)
			}
		}
	}
	// 增幅结束，处理反击技能
	if HpCounterSkill != nil && len(HpCounterSkill) > 0 {
		// var CounterHurtArr []*m.HurtAttr
		var counterSkill *m.CardMonsterSkill
		for _, skill := range monster.Skills {
			if skill.Tid == 250301 { // 反击
				counterSkill = skill
			}
		}
		if counterSkill == nil {
			return
		}
		if counterSkill.ExtVal < 0 {
			return
		}
		for skillId, skill := range HpCounterSkill {
			counterThreshold := int64(skill.Key) // 反击伤害阈值
			counterTime := int64(skill.Value)    // 反击次数
			if cardGame.Monster.HurtSum >= counterThreshold && counterSkill.ExtVal >= 0 {
				cardGame.Monster.HurtSum = 0
				counterSkill.ExtVal = -1 // 标识为本回合，反击不可用
				if CounterHurtArr == nil {
					CounterHurtArr = make([]*m.HurtAttr, 0)
				}
				for i := 0; i < int(counterTime); i++ {
					monsterCounter := &m.HurtAttr{
						Tid:          skillId, // 反击视为反击攻击
						Target:       int64(data.BSCardEffectTargetEnum.Player),
						HurtType:     int64(data.BSCardHurtTypeEnum.Hurt),
						Typ:          1,
						Val:          monster_GetRealAtt_BSGame(cardGame, monsterConfig), // 攻击力
						ShieldHurt:   0,
						CanBloodSuck: 1, // 反击允许吸血
						CanFightBack: 1, // 0-支持反击 1-不支持反击
					}
					monsterCounter.EffectBuff = make(map[int64]int64, 0)
					monsterCounter.EffectBuff[skillId] = 1
					CounterHurtArr = append(CounterHurtArr, monsterCounter)
				}
			}
		}
	}
	if CounterHurtArr != nil && len(CounterHurtArr) > 0 {
		// 只发送怪物反击的数据，
		CounterHurtArr = monster_whenAtk_BSGame(cardGame, CounterHurtArr, monsterConfig) // 修正数值，怪物攻击
		// 处理完后，加回去原攻击数据中
		for _, hurtInfo := range CounterHurtArr {
			orgHurtLst = append(orgHurtLst, hurtInfo)
		}
		hattrs = orgHurtLst
	}
	return
}

// 玩家受到伤害--扣金币
func player_whenHurt_BSGame(cardGame *m.BSGame, orgHurtLst []*m.HurtAttr, monsterConfig data.CardMonster) (hattrs []*m.HurtAttr) {
	activeBuffMap := make(map[int64]int64, 0) // 玩家buff激活缓存 -key buffTid  -value Val即Buff的值（层）
	dmgMissPercentLst := make([]int64, 0)     // 百分比闪避
	dmgBlockPercentLst := make([]int64, 0)    // 百分比减免
	dmgBlockPointLst := make([]int64, 0)      // 数值减免
	fightBackLst := make([]int64, 0)          // 反击
	// userGold, _ := GetUserGold(cardGame.Uid.Hex())
	hattrs = orgHurtLst
	defer cardGame.Update(cardGame)
	//--buff搜索--
	for _, cardBuff := range cardGame.CardBuffs {
		// buff已失效
		if cardBuff.UseRound <= 0 {
			continue
		}
		// 得到卡的配置表内容，其实玩家的buff就是卡
		tpl1, ok := data.Get("BossSlotCards", uint64(cardBuff.Tid))
		if !ok {
			continue
		}
		cardConfig := tpl1.(data.BossSlotCard)
		// 非装备卡，不影响伤害数值
		if int64(cardConfig.CardTyp) != data.BSCardTypeEnum.Equip {
			continue
		}
		// 检查生效时机
		var checkPoint int64 = int64(cardConfig.CheckPoint)
		if checkPoint != data.BSCardMonsterSkillCheckPointEnum.WhenHurt {
			continue
		}
		var tempId int64 = int64(cardBuff.Tid)
		_, findBuffExist := activeBuffMap[tempId]
		if findBuffExist == false {
			activeBuffMap[tempId] = cardBuff.Val
		} else {
			activeBuffMap[tempId] = (activeBuffMap[tempId] + cardBuff.Val)
		}
		for _, hurtTypeValue := range cardConfig.HurtTyp {
			hurtType64 := int64(hurtTypeValue)
			var buffCeng int = int(cardBuff.Val) // buff的层数 -- 只有可叠加的技能（statusTime = 99.eg:魔法屏障）的层数可能大于1，其余都为1
			if cardConfig.StatusTime != 99 {
				buffCeng = 1
			}
			// 闪避类技能  dmgMissPercentMap
			if hurtType64 == data.BSCardHurtTypeEnum.DmgMissPercent || hurtType64 == data.BSCardHurtTypeEnum.DmgMissPercentOnce {
				for i := 0; i < buffCeng; i++ {
					dmgMissPercentLst = append(dmgMissPercentLst, tempId)
				}
			}
			// 格挡（百分比减免）
			if hurtType64 == data.BSCardHurtTypeEnum.DmgBlockPercent || hurtType64 == data.BSCardHurtTypeEnum.DmgBlockPercentOnce {
				for i := 0; i < buffCeng; i++ {
					dmgBlockPercentLst = append(dmgBlockPercentLst, tempId)
				}
			}
			// 防御（数值减免)
			if hurtType64 == data.BSCardHurtTypeEnum.DmgBlockPoint || hurtType64 == data.BSCardHurtTypeEnum.DmgBlockPointOnce {
				for i := 0; i < buffCeng; i++ {
					dmgBlockPointLst = append(dmgBlockPointLst, tempId)
				}
			}
			// 反击
			if hurtType64 == data.BSCardHurtTypeEnum.FightBack {
				for i := 0; i < buffCeng; i++ {
					fightBackLst = append(fightBackLst, tempId)
				}
			}
		}

	}
	// 伤害处理---（1）百分比减免（2）数值减免（3）闪避
	FightBackArr := make([]*m.HurtAttr, 0)
	var hashBlockPointOnce bool = false
	var hasBlockOnce bool = false
	var hasMissOnce bool = false
	for _, hurtInfo := range orgHurtLst {

		if int64(hurtInfo.Val) <= 0 {
			continue
		}
		if int64(hurtInfo.Target) != data.BSCardEffectTargetEnum.Player {
			continue
		}
		if int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.Hurt { // 对玩家的伤害类型为  Hurt伤害
			// 处理闪避
			if len(dmgMissPercentLst) > 0 && int64(hurtInfo.Val) > 0 {
				for _, buffTid := range dmgMissPercentLst {
					tpl1, ok := data.Get("BossSlotCards", uint64(buffTid))
					if !ok {
						continue
					}
					cardConfig := tpl1.(data.BossSlotCard)
					for _, hurtTypeValue := range cardConfig.HurtTyp {
						hurtType64 := int64(hurtTypeValue)
						if hurtType64 == data.BSCardHurtTypeEnum.DmgMissPercent {
							for _, theConfig := range cardConfig.Hurt {
								if int64(theConfig.HurtTyp) == hurtType64 && int64(hurtInfo.Val) > 0 {
									val, _, _ := getCardHurt_BSGame(theConfig, int64(monsterConfig.Race), int64(cardConfig.HurtRace))
									if utils.RandomInt64(0, 100) < val {
										hurtInfo.Val = 0
										if hurtInfo.EffectBuff == nil {
											hurtInfo.EffectBuff = make(map[int64]int64, 0)
										}
										hurtInfo.EffectBuff[buffTid] = 1
										hurtInfo.ValType = 1
										// fmt.Printf("玩家因[%d]闪避了攻击", buffTid)
									}
								}
							}
						}
						if hurtType64 == data.BSCardHurtTypeEnum.DmgMissPercentOnce {

							for _, theConfig := range cardConfig.Hurt {
								if int64(theConfig.HurtTyp) == hurtType64 && int64(hurtInfo.Val) > 0 && hasMissOnce == false {
									val, _, _ := getCardHurt_BSGame(theConfig, int64(monsterConfig.Race), int64(cardConfig.HurtRace))
									if utils.RandomInt64(0, 100) < val {
										hurtInfo.Val = 0
										if hurtInfo.EffectBuff == nil {
											hurtInfo.EffectBuff = make(map[int64]int64, 0)
										}
										hurtInfo.EffectBuff[buffTid] = 1
										hurtInfo.ValType = 1
										// fmt.Printf("玩家因[%d]闪避了攻击", buffTid)
										hasMissOnce = true
									}
								}
							}
							// 只要有一段伤害，触发了“下一次攻击闪避”，删除所有该BUFF
							if hasMissOnce {
								playerBuff_Del_BSGame(cardGame, buffTid)
							}
						}
					}
				}
			}
			// 处理格挡（百分比减免）
			if len(dmgBlockPercentLst) > 0 && int64(hurtInfo.Val) > 0 {
				for _, buffTid := range dmgBlockPercentLst {
					tpl1, ok := data.Get("BossSlotCards", uint64(buffTid))
					if !ok {
						continue
					}
					cardConfig := tpl1.(data.BossSlotCard)
					for _, hurtTypeValue := range cardConfig.HurtTyp {
						hurtType64 := int64(hurtTypeValue)
						if hurtType64 == data.BSCardHurtTypeEnum.DmgBlockPercent {
							for _, theConfig := range cardConfig.Hurt {
								if int64(theConfig.HurtTyp) == hurtType64 && int64(hurtInfo.Val) > 0 {
									val, _, _ := getCardHurt_BSGame(theConfig, int64(monsterConfig.Race), int64(cardConfig.HurtRace))
									var realHurt int64 = int64(float64(hurtInfo.Val) * float64(100-val) / float64(100))
									hurtInfo.Val = realHurt
									if hurtInfo.EffectBuff == nil {
										hurtInfo.EffectBuff = make(map[int64]int64, 0)
									}
									hurtInfo.EffectBuff[buffTid] = 1
								}
							}
						}
						if hurtType64 == data.BSCardHurtTypeEnum.DmgBlockPercentOnce {
							for _, theConfig := range cardConfig.Hurt {
								if int64(theConfig.HurtTyp) == hurtType64 && int64(hurtInfo.Val) > 0 && hasBlockOnce == false {
									val, _, _ := getCardHurt_BSGame(theConfig, int64(monsterConfig.Race), int64(cardConfig.HurtRace))
									var realHurt int64 = int64(float64(hurtInfo.Val) * float64(100-val) / float64(100))
									hurtInfo.Val = realHurt
									if hurtInfo.EffectBuff == nil {
										hurtInfo.EffectBuff = make(map[int64]int64, 0)
									}
									hurtInfo.EffectBuff[buffTid] = 1
									hasBlockOnce = true
								}
							}
							if hasBlockOnce {
								playerBuff_Del_BSGame(cardGame, buffTid)
							}
						}
					}
				}
			}
			// 处理防御（数值减免)
			if len(dmgBlockPointLst) > 0 && int64(hurtInfo.Val) > 0 {
				for _, buffTid := range dmgBlockPointLst {
					tpl1, ok := data.Get("BossSlotCards", uint64(buffTid))
					if !ok {
						continue
					}
					cardConfig := tpl1.(data.BossSlotCard)
					for _, hurtTypeValue := range cardConfig.HurtTyp {
						hurtType64 := int64(hurtTypeValue)
						if hurtType64 == data.BSCardHurtTypeEnum.DmgBlockPoint {
							for _, theConfig := range cardConfig.Hurt {
								if int64(theConfig.HurtTyp) == hurtType64 && int64(hurtInfo.Val) > 0 {
									val, _, _ := getCardHurt_BSGame(theConfig, int64(monsterConfig.Race), int64(cardConfig.HurtRace))
									var realHurt int64 = hurtInfo.Val - val
									if realHurt <= 0 {
										realHurt = 0
									}
									hurtInfo.Val = realHurt
									if hurtInfo.EffectBuff == nil {
										hurtInfo.EffectBuff = make(map[int64]int64, 0)
									}
									hurtInfo.EffectBuff[buffTid] = 1
								}
							}
						}
						if hurtType64 == data.BSCardHurtTypeEnum.DmgBlockPointOnce {
							for _, theConfig := range cardConfig.Hurt {
								if int64(theConfig.HurtTyp) == hurtType64 && int64(hurtInfo.Val) > 0 && hashBlockPointOnce == false {
									val, _, _ := getCardHurt_BSGame(theConfig, int64(monsterConfig.Race), int64(cardConfig.HurtRace))
									var realHurt int64 = hurtInfo.Val - val
									if realHurt <= 0 {
										realHurt = 0
									}
									hurtInfo.Val = realHurt
									if hurtInfo.EffectBuff == nil {
										hurtInfo.EffectBuff = make(map[int64]int64, 0)
									}
									hurtInfo.EffectBuff[buffTid] = 1
									hashBlockPointOnce = true
								}
							}
							if hashBlockPointOnce {
								playerBuff_Del_BSGame(cardGame, buffTid)
							}
						}
					}
				}
			}
			// 处理玩家护盾
			if int64(hurtInfo.Val) > 0 && cardGame.PlayerShield > 0 {
				var hurtNum int64 = int64(hurtInfo.Val)
				if hurtNum <= cardGame.PlayerShield {
					hurtInfo.Val = 0
					cardGame.PlayerShield = (cardGame.PlayerShield - hurtNum)
					if cardGame.PlayerShield <= 0 {
						cardGame.PlayerShield = 0
					}
					hurtInfo.ShieldHurt = hurtNum
					if hurtInfo.EffectBuff == nil {
						hurtInfo.EffectBuff = make(map[int64]int64, 0)
					}
					hurtInfo.EffectBuff[260030] = 1
				} else {
					shieldHurt := cardGame.PlayerShield
					hurtInfo.Val = hurtNum - shieldHurt
					cardGame.PlayerShield = 0
					hurtInfo.ShieldHurt = hurtNum
					if hurtInfo.EffectBuff == nil {
						hurtInfo.EffectBuff = make(map[int64]int64, 0)
					}
					hurtInfo.EffectBuff[260030] = 1
				}
			}
			// 反击 -- 无需判断是否为有效伤害val > 0
			if len(fightBackLst) > 0 && hurtInfo.CanFightBack == 0 {
				for _, buffTid := range fightBackLst {
					tpl1, ok := data.Get("BossSlotCards", uint64(buffTid))
					if !ok {
						continue
					}
					cardConfig := tpl1.(data.BossSlotCard)
					for _, hurtTypeValue := range cardConfig.HurtTyp {
						hurtType64 := int64(hurtTypeValue)
						if hurtType64 == data.BSCardHurtTypeEnum.FightBack {
							for _, theConfig := range cardConfig.Hurt {
								if int64(theConfig.HurtTyp) == hurtType64 {
									val, valSupport, valInfoKey := getCardHurt_BSGame(theConfig, int64(monsterConfig.Race), int64(cardConfig.HurtRace))
									repit := utils.RandomInt64(int64(cardConfig.HurtRepetition.Min), int64(cardConfig.HurtRepetition.Max))
									repit = repit + 1
									for i := 0; i < int(repit); i++ {
										newHurtObj := &m.HurtAttr{
											Tid:          int64(cardConfig.Id),     // 卡牌/技能ID
											Target:       int64(theConfig.Target),  // 作用对象
											HurtType:     int64(theConfig.HurtTyp), // 伤害数值类型
											Typ:          valInfoKey,               // 伤害详细类型 1 固定伤害 2 连续伤害 3 额外伤害
											Val:          val,                      // 伤害数值
											ValSupport:   valSupport,               // 辅助数值
											ShieldHurt:   0,                        // 对护盾伤害
											EffectBuff:   make(map[int64]int64, 0), // key-buffId value-1-受此buff影响
											IsTrapVal:    1,                        // 标识为陷阱伤害，意味着不吃弱点
											CanFightBack: 1,                        // 0-支持被反击 1-不能被反击
											SpAtkTyp:     CombatSpAtkTypFormat(cardConfig.SpHurtTyp),
										}
										newHurtObj.EffectBuff[buffTid] = 1
										FightBackArr = append(FightBackArr, newHurtObj)
									}
								}
							}
						}
					}
				}
			}
		}
	}
	if len(FightBackArr) > 0 {
		FightBackArr = player_whenUseCard_BSGame(cardGame, FightBackArr)
		for _, hurtInfo := range FightBackArr {
			orgHurtLst = append(orgHurtLst, hurtInfo)
		}
	}
	// 处理结束，重新赋值
	hattrs = orgHurtLst
	//扣金币，判死
	var monsterHurtSum int64 = 0
	for _, hurtInfo := range orgHurtLst {
		// fmt.Println("PlayerWhenHurt:", hurtInfo.Tid)
		if int64(hurtInfo.Target) != data.BSCardEffectTargetEnum.Player {
			continue
		}
		if int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.Hurt {
			hurtNum := int64(hurtInfo.Val)
			if hurtNum > 0 {
				monsterHurtSum = monsterHurtSum + hurtNum
			}
		}
	}
	if monsterHurtSum >= cardGame.HP {
		return
	}
	// 尖刺陷阱，伤害类型定义为15-反击，不领出来单独处理了。改为统一处理
	if len(FightBackArr) > 0 {
		orgHurtLst = monster_whenHurt_BSGame(cardGame, orgHurtLst, monsterConfig)
		hattrs = orgHurtLst
	}
	return
}

// 当玩家使用卡牌
func player_whenUseCard_BSGame(cardGame *m.BSGame, orgHurtLst []*m.HurtAttr) (hattrs []*m.HurtAttr) {
	activeBuffMap := make(map[int64]int64, 0) // 玩家buff激活缓存 -key buffTid  -value Val即Buff的值（层）

	for _, cardBuff := range cardGame.CardBuffs {
		if cardBuff.UseRound <= 0 { // 失效技能，UseRound不是CD,UseRound是剩余回合，有值，buff才会生效
			continue
		}
		// 得到卡的配置表内容，其实玩家的buff就是卡
		tpl1, ok := data.Get("BossSlotCards", uint64(cardBuff.Tid))
		if !ok {
			continue
		}
		cardConfig := tpl1.(data.BossSlotCard)
		if int64(cardConfig.CardTyp) != data.BSCardTypeEnum.Equip || // 非装备卡，不影响伤害数值
			int64(cardConfig.CheckPoint) != data.BSCardMonsterSkillCheckPointEnum.WhenAtk {
			continue
		}
		var tempId int64 = cardBuff.Tid
		_, findBuffExist := activeBuffMap[tempId]
		if findBuffExist {
			activeBuffMap[tempId] += cardBuff.Val
		} else {
			activeBuffMap[tempId] = cardBuff.Val
		}
	}
	// 计算伤害*老虎机倍率*老虎机伤害加成
	orgHurtLst = fixedCardHurt_SpinDmg_BSGame(cardGame, orgHurtLst) // 弱点
	// 物料准备结束，按照下列函数执行顺序，确定优先级
	orgHurtLst = fixedCardHurt_Weakness_BSGame(260017, cardGame, orgHurtLst, activeBuffMap)     // 弱点
	orgHurtLst = fixedCardHurt_Weakness_BSGame(270017, cardGame, orgHurtLst, activeBuffMap)     // 弱点+
	orgHurtLst = fixedCardHurt_NaturalEnemy_BSGame(260012, cardGame, orgHurtLst, activeBuffMap) // 物竞天择
	orgHurtLst = fixedCardHurt_NaturalEnemy_BSGame(270012, cardGame, orgHurtLst, activeBuffMap) // 物竞天择+
	orgHurtLst = fixedCardHurt_Bleeding_BSGame(5001, cardGame, orgHurtLst, activeBuffMap)       // 流血
	orgHurtLst = fixedCardHurt_Bleeding_BSGame(270020, cardGame, orgHurtLst, activeBuffMap)     // 流血+
	// orgHurtLst = fixedCardHurt_WorldBoss_PlayerDmgAccu_BSGame(cardGame, orgHurtLst)
	hattrs = orgHurtLst

	cardGame.Update(cardGame)
	return
}

// 获取怪物真实伤害（配表伤害 + 永久加成百分比）
func monster_GetRealAtt_BSGame(cardGame *m.BSGame, monsterConfig data.CardMonster) (att int64) {
	orgAtt := monsterConfig.Att
	attBrustPercent := cardGame.Monster.AttBrustPermanent      // 血线增伤
	attBurstHpPointPercent := cardGame.Monster.AttBrustHpPoint // 精准血量增伤
	if attBurstHpPointPercent > 0 {
		attBrustPercent = attBrustPercent + attBurstHpPointPercent
	}
	att = int64(orgAtt) + int64(orgAtt)*attBrustPercent/100
	if cardGame.Spin > 1 { // 老虎机倍率加倍伤害
		att *= cardGame.Spin
	}
	return
}

// 获取怪物真实伤害（配表伤害 + 永久加成百分比 + 临时增幅百分比）
func monster_GetRealAttWithTempBrust_BSGame(cardGame *m.BSGame, monsterConfig data.CardMonster, tempBrustPercent int64) (att int64) {
	orgAtt := monsterConfig.Att
	attBrustPercent := cardGame.Monster.AttBrustPermanent      // 血线增伤
	attBurstHpPointPercent := cardGame.Monster.AttBrustHpPoint // 精准血量增伤
	if tempBrustPercent > 0 {
		attBrustPercent = attBrustPercent + tempBrustPercent
	}
	if attBurstHpPointPercent > 0 {
		attBrustPercent = attBrustPercent + attBurstHpPointPercent
	}
	att = int64(orgAtt) + int64(orgAtt)*attBrustPercent/100
	if cardGame.Spin > 1 { // 老虎机倍率加倍伤害
		att *= cardGame.Spin
	}
	return
}

// 玩家使用卡牌--修正伤害数据--260014尖刺陷阱
func fixedCardHurt_SpearTrap_BSGame(cardGame *m.BSGame, orgHurtLst []*m.HurtAttr, activeBuffMap map[int64]int64) (active bool, hattrs []*m.HurtAttr) {
	active = false
	hattrs = orgHurtLst
	var buffId int64 = int64(260014)
	//造成200伤害，被攻击时触发
	_, ok := activeBuffMap[buffId]
	if ok == false {
		return
	}
	// 获得怪物信息
	monster := cardGame.Monster
	monsterTpl, ok := data.Get("CardMonsters", uint64(monster.Tid))
	if !ok {
		return
	}
	monsterConfig := monsterTpl.(data.CardMonster) // 获得怪物配置表信息
	// 得到卡的配置表内容，其实玩家的buff就是卡
	tpl1, ok := data.Get("BossSlotCards", uint64(buffId))
	if !ok {
		return
	}
	cardConfig := tpl1.(data.BossSlotCard)
	//
	hurtValue, hurtValueSupport, hurtInfoKey := getCardHurt_BSGame(cardConfig.Hurt[0], int64(monsterConfig.Race), int64(cardConfig.HurtRace))
	buffVal := activeBuffMap[buffId] // 层数
	hurtValue = (hurtValue * buffVal)
	//追加伤害
	newHurt := &m.HurtAttr{
		Tid:        buffId,
		Target:     int64(data.BSCardEffectTargetEnum.Monster),
		HurtType:   int64(data.BSCardHurtTypeEnum.Hurt),
		Typ:        hurtInfoKey,
		Val:        hurtValue,
		ValSupport: hurtValueSupport,
		IsTrapVal:  1,
		SpAtkTyp:   CombatSpAtkTypFormat(cardConfig.SpHurtTyp),
	}
	newHurt.EffectBuff = make(map[int64]int64, 0)
	newHurt.EffectBuff[buffId] = 1
	orgHurtLst = append(orgHurtLst, newHurt)
	hattrs = orgHurtLst
	active = true
	return active, hattrs
}

// 玩家使用卡牌--修正伤害数据--260012物竞天择
func fixedCardHurt_NaturalEnemy_BSGame(naturalBuffId int64, cardGame *m.BSGame, orgHurtLst []*m.HurtAttr, activeBuffMap map[int64]int64) (hattrs []*m.HurtAttr) {
	var buffId int64 = naturalBuffId //260012 270012
	hattrs = orgHurtLst
	// 物竞天择--种族伤害额外触发1次，可叠加
	_, ok := activeBuffMap[buffId]
	if ok == false {
		return
	}
	buffVal := activeBuffMap[buffId] // 层数
	// 遍历所有伤害数据，找到，伤害类型为RaceHurt的卡牌伤害
	addHurtLst := make([]*m.HurtAttr, 0)
	for _, hurtInfo := range orgHurtLst {
		if int64(hurtInfo.Target) == data.BSCardEffectTargetEnum.Monster { // 对象是怪物的，才会生效
			if int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.RaceHurt { // 伤害类型是种族伤害，才会生效
				if hurtInfo.Val <= 0 { // 非有效伤害跳过--得到初始数据的时候，已经把种族伤害处理了

				} else {
					//[]*m.HurtAttr 是指针的数组，要new一个，要不外部引用会引用回同一个
					newHurtObj := &m.HurtAttr{
						Tid:        hurtInfo.Tid,
						Target:     hurtInfo.Target,
						HurtType:   hurtInfo.HurtType,
						Typ:        hurtInfo.Typ,
						Val:        hurtInfo.Val,
						ShieldHurt: 0,
					}
					addHurtLst = append(addHurtLst, newHurtObj)
				}
			}
		}
	}
	// 追加物竞天择层数次数
	if len(addHurtLst) > 0 && buffVal > 0 {
		for _, hurtInfo := range addHurtLst {
			for i := 0; i < int(buffVal); i++ {
				//[]*m.HurtAttr 是指针的数组，要new一个，要不外部引用会引用回同一个
				newHurtObj := &m.HurtAttr{
					Tid:        hurtInfo.Tid,
					Target:     hurtInfo.Target,
					HurtType:   hurtInfo.HurtType,
					Typ:        hurtInfo.Typ,
					Val:        hurtInfo.Val,
					ShieldHurt: 0,
				}
				newEffectBuff := make(map[int64]int64, 0)
				newEffectBuff[buffId] = 1
				newHurtObj.EffectBuff = newEffectBuff
				orgHurtLst = append(orgHurtLst, newHurtObj)
			}
		}
		hattrs = orgHurtLst
	}
	return
}

// 玩家使用卡牌--修正伤害数据--260017弱点
func fixedCardHurt_Weakness_BSGame(weaknessBuffId int64, cardGame *m.BSGame, orgHurtLst []*m.HurtAttr, activeBuffMap map[int64]int64) (hattrs []*m.HurtAttr) {
	var buffId int64 = weaknessBuffId // 260017弱点 270017 弱点+
	hattrs = orgHurtLst
	// 弱点--下张卡牌造成的伤害加倍
	_, ok := activeBuffMap[buffId]
	if ok == false {
		return
	}
	buffVal := activeBuffMap[buffId] // 层数
	//fmt.Printf("弱点，层数 = %d \n", buffVal)
	buffVal = (buffVal * 2) // 实际倍率为，2倍 * 层数
	//fmt.Printf("弱点，最终加成倍率 = %d \n", buffVal)
	// 遍历所有伤害数据，只处理第一个，卡牌Tid相同，伤害类型为Hurt的卡牌伤害
	var hurtCardTid int64 = -1
	for _, hurtInfo := range orgHurtLst {
		if hurtInfo.IsTrapVal != 0 { // 不处理陷阱伤害
			continue
		}
		if int64(hurtInfo.Target) == data.BSCardEffectTargetEnum.Monster { // 对象是怪物的，才会生效
			if int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.Hurt ||
				int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.RaceHurt ||
				int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.FightBack { // 伤害数据
				if hurtInfo.Val <= 0 { // 非有效伤害跳过
					continue
				}
				hurtCardTid = hurtInfo.Tid
				break
			}
		}
	}
	if hurtCardTid != -1 {
		// 实施弱点
		for _, hurtInfo := range orgHurtLst {
			if hurtInfo.Tid == hurtCardTid {
				if int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.Hurt ||
					int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.RaceHurt ||
					int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.FightBack {
					//fmt.Printf("实施弱点，初始伤害 = %d \n", hurtInfo.Val)
					hurtInfo.Val = (hurtInfo.Val * buffVal)
					//fmt.Printf("实施弱点，加成倍率 = %d, 最终伤害 = %d \n", buffVal, hurtInfo.Val)
					if hurtInfo.EffectBuff == nil {
						hurtInfo.EffectBuff = make(map[int64]int64, 0)
					}
					hurtInfo.EffectBuff[buffId] = 1
				}
			}
		}
		// 使用弱点后，消除玩家buff
		playerBuff_Del_BSGame(cardGame, buffId)
		hattrs = orgHurtLst
	}
	return
}

// 玩家使用卡牌--修正伤害数据--260020流血
func fixedCardHurt_Bleeding_BSGame(bleedingBuffId int64, cardGame *m.BSGame, orgHurtLst []*m.HurtAttr, activeBuffMap map[int64]int64) (hattrs []*m.HurtAttr) {
	var buffId int64 = bleedingBuffId // 5001 270020
	hattrs = orgHurtLst
	// 流血
	buffVal, ok := activeBuffMap[buffId] // 追加伤害
	if ok == false {
		return
	}
	// 遍历所有伤害数据，伤害类型为Hurt的卡牌伤害
	for _, hurtInfo := range orgHurtLst {
		if int64(hurtInfo.Target) == data.BSCardEffectTargetEnum.Monster { // 对象是怪物的，才会生效
			if int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.Hurt ||
				int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.RaceHurt ||
				int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.FightBack { // 伤害数据
				if hurtInfo.Val <= 0 { // 非有效伤害跳过
					continue
				}
				hurtInfo.Val = hurtInfo.Val + buffVal // 伤害追加
				if hurtInfo.EffectBuff == nil {
					hurtInfo.EffectBuff = make(map[int64]int64, 0)
				}
				hurtInfo.EffectBuff[buffId] = 1
			}
		}
	}
	hattrs = orgHurtLst
	return
}

// 计算 伤害*老虎机倍率*老虎机伤害加成
func fixedCardHurt_SpinDmg_BSGame(cardGame *m.BSGame, orgHurtLst []*m.HurtAttr) (hattrs []*m.HurtAttr) {
	if cardGame.DmgBonus > 0 {
		for _, hurtInfo := range orgHurtLst {
			if int64(hurtInfo.Target) == data.BSCardEffectTargetEnum.Monster { // 对象是怪物的，才会生效
				if int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.Hurt ||
					int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.RaceHurt ||
					int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.FightBack { // 伤害数据
					if hurtInfo.Val <= 0 { // 非有效伤害跳过
						continue
					}
					realAtt := hurtInfo.Val * cardGame.Spin * (100 + cardGame.DmgBonus) / 100
					hurtInfo.Val = realAtt // 伤害追加
				}
			}
		}
	}
	hattrs = orgHurtLst
	return
}

func fixedCardHurt_WorldBoss_PlayerDmgAccu_BSGame(cardGame *m.BSGame, orgHurtLst []*m.HurtAttr) (hattrs []*m.HurtAttr) {
	if cardGame.AttBrustPercent > 0 {
		for _, hurtInfo := range orgHurtLst {
			if int64(hurtInfo.Target) == data.BSCardEffectTargetEnum.Monster { // 对象是怪物的，才会生效
				if int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.Hurt ||
					int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.RaceHurt ||
					int64(hurtInfo.HurtType) == data.BSCardHurtTypeEnum.FightBack { // 伤害数据
					if hurtInfo.Val <= 0 { // 非有效伤害跳过
						continue
					}
					orgAtt := hurtInfo.Val
					// realAtt := orgAtt + int64(float64(orgAtt*cardGame.DmgBonus)/float64(100))
					realAtt := orgAtt * (100 + cardGame.AttBrustPercent) / 100
					hurtInfo.Val = realAtt // 伤害追加
				}
			}
		}
	}
	hattrs = orgHurtLst
	return
}

// 新增玩家buff
func playerBuff_Add_BSGame(cardGame *m.BSGame) {

}

// 删除玩家buff
func playerBuff_Del_BSGame(cardGame *m.BSGame, buffTid int64) {
	cardBuffs := make([]*m.CardBuff, 0)
	defer cardGame.Update(cardGame)
	for _, itemBuff := range cardGame.CardBuffs {
		if itemBuff.Tid == buffTid {
			continue
		}
		cardBuffs = append(cardBuffs, itemBuff)
	}
	cardGame.CardBuffs = cardBuffs
}

// 刷新玩家buff显示
func reflashBuffShow_Player_BSGame(cardGame *m.BSGame) {
	defer cardGame.Update(cardGame)
	var isShieldBuffExist bool = false
	for _, buff := range cardGame.CardBuffs {
		tpl, ok := data.Get("BossSlotCards", uint64(buff.Tid))
		if !ok {
			//fmt.Println(errors.NewErrcode(data.Errcode.ConfigNotFound, fmt.Sprintf("没有找到用户buff配置信息，tid:%d", buff.Tid)))
			buff.ShowVal = 0
			continue
		}
		cardConfig := tpl.(data.BossSlotCard)
		//
		switch buff.CardType {
		case data.BSCardTypeEnum.Trap: // 陷阱卡
			buff.ShowVal = buff.UseRound
		case data.BSCardTypeEnum.ContinuousTrap: // 永续陷阱卡
			buff.ShowVal = buff.Val
		case data.BSCardTypeEnum.Spell: // 魔法卡
			buff.ShowVal = 0
		case data.BSCardTypeEnum.Equip: // 装备卡
			if cardConfig.StatusTime == 99 {
				buff.ShowVal = buff.Val
			} else {
				buff.ShowVal = buff.UseRound
				if buff.ShowVal == 1 {
					buff.ShowVal = 0
				}
			}
		default:
			buff.ShowVal = 0
		}
		//护盾--全部用260030的配置生成
		if buff.Tid == 260030 {
			isShieldBuffExist = true
		}
	}
	// 玩家护盾检测--全部用260030的配置生成
	if cardGame.PlayerShield > 0 {
		if isShieldBuffExist {
			// 列表中护盾buff，修改显示值
			for _, buff := range cardGame.CardBuffs {
				if buff.Tid == 260030 {
					buff.ShowVal = cardGame.PlayerShield
				}
			}
		} else {
			// 列表中没有护盾buff,新增护盾buff
			newCardBuff := &m.CardBuff{
				Tid:      int64(260030),
				CardType: int64(data.BSCardTypeEnum.Atk),
				UseRound: int64(99),
				Val:      int64(1),
				ShowVal:  cardGame.PlayerShield,
			}
			cardGame.CardBuffs = append(cardGame.CardBuffs, newCardBuff)
		}
	} else {
		cardGame.PlayerShield = 0
		if isShieldBuffExist {
			// 列表中有护盾buff,但是当前护盾为0，删除护盾buff
			cardBuffs := make([]*m.CardBuff, 0)
			for _, itemBuff := range cardGame.CardBuffs {
				if itemBuff.Tid == 260030 {
					continue
				}
				cardBuffs = append(cardBuffs, itemBuff)
			}
			cardGame.CardBuffs = cardBuffs
		}
	}
}

// 怪物增加/累加技能数值
func MonsterBuff_Add_BSGame(cardGame *m.BSGame, skillconfig data.CardMonsterSkill, val int64, stayRound int64) {
	if cardGame.Monster.Skills == nil {
		cardGame.Monster.Skills = make(map[int64]*m.CardMonsterSkill, 0)
	}
	skillTid := int64(skillconfig.Id)
	skillTyp := int64(skillconfig.SkillTyp)

	theSkill, find := cardGame.Monster.Skills[skillTid]
	if find && theSkill != nil {
		// 永久技能
		if skillconfig.StayRound == 99 {
			theSkill.Val = theSkill.Val + val
			if theSkill.Val < 1 {
				theSkill.Val = 1
			}
			// 永久技能，不处理持续回合数变更
			// theSkill.StayRound = theSkill.StayRound + stayRound
		}
		// 短暂技能
		if skillconfig.StayRound != 99 {
			theSkill.StayRound = theSkill.StayRound + stayRound
			if theSkill.StayRound < 0 {
				theSkill.StayRound = 0
			}
			// 短暂技能，不处理层数变更
			// theSkill.Val = theSkill.Val + val
		}
		cardGame.Monster.Skills[skillTid] = theSkill
	} else {
		newSkill := &m.CardMonsterSkill{
			Tid:       skillTid,
			Cd:        int64(skillconfig.Cd),
			Val:       val,
			ExtVal:    0,
			ShowValue: 0,
			SkillTyp:  skillTyp,
			StayRound: stayRound,
		}
		if skillconfig.StayRound == 99 {
			newSkill.StayRound = 99
		} else {
			newSkill.Val = 1
		}
		// 反击
		if skillTyp == data.BSCardMonsterSkillEnum.Hp_counter {
			newSkill.ExtVal = int64(skillconfig.Vals[0])
		}
		// 首回合护盾
		if skillTyp == data.BSCardMonsterSkillEnum.Shield_firstTurn {
			cardGame.Monster.Shield = cardGame.Monster.Shield + int64(skillconfig.Vals[0])
		}
		// 护盾反伤
		if skillTyp == data.BSCardMonsterSkillEnum.Shield_fightBack {
			newSkill.ExtVal = int64(skillconfig.Vals[1])
		}
		cardGame.Monster.Skills[skillTid] = newSkill
	}
}

// 刷新怪兽buff显示
func reflashBuffShow_Monster_BSGame(cardGame *m.BSGame) {
	defer cardGame.Update(cardGame)
	for _, skill := range cardGame.Monster.Skills {
		skillTpl, ok := data.Get("CardMonsterSkills", uint64(skill.Tid))
		if !ok {
			//fmt.Println(errors.NewErrcode(data.Errcode.ConfigNotFound, fmt.Sprintf("没有找到怪物技能信息，tid:%d", skill.Tid)))
			skill.ShowValue = 0
			continue
		}
		skillT := skillTpl.(data.CardMonsterSkill)
		var skillTyp int64 = int64(skillT.SkillTyp)
		switch skillTyp {
		case data.BSCardMonsterSkillEnum.Attack_normal: // 1.普通攻击
			skill.ShowValue = 0
		case data.BSCardMonsterSkillEnum.Attack_time_dmgAccumulation: // 2.弱点连射，弱点攻击
			skill.ShowValue = 0
		case data.BSCardMonsterSkillEnum.Attack_recover_dmgUp: // 3.嗜血，狂怒，不死
			skill.ShowValue = skill.Cd
		case data.BSCardMonsterSkillEnum.Attack_time: // 4.连射，狂抓，旋风斩
			skill.ShowValue = skill.Cd
		case data.BSCardMonsterSkillEnum.Attack_recover: // 5.吸血
			skill.ShowValue = int64(skillT.Vals[0])
		case data.BSCardMonsterSkillEnum.Steal_gold: // 6.贪婪
			skill.ShowValue = skill.Cd
		case data.BSCardMonsterSkillEnum.Mana_destroy: // 7.贪婪
			skill.ShowValue = skill.Cd
		case data.BSCardMonsterSkillEnum.Card_destroy: // 8.龙息
			skill.ShowValue = skill.Cd
		case data.BSCardMonsterSkillEnum.Ceiling: // 9.屏障，守护，潮汐之力
			skill.ShowValue = int64(skillT.Vals[0])
		case data.BSCardMonsterSkillEnum.Block: // 10.石肤，格挡
			skill.ShowValue = int64(skillT.Vals[0])
		case data.BSCardMonsterSkillEnum.Blocking: // 11.守护
			skill.ShowValue = int64(skillT.Vals[0])
		case data.BSCardMonsterSkillEnum.Hp_sub_dmgAccumulation: // 12.记仇，全力以赴，垂死挣扎
			skill.ShowValue = 0
		case data.BSCardMonsterSkillEnum.Hp_counter: // 13.反击
			if skill.ExtVal >= 0 { // 没触发过反击
				hurtLine := int64(skillT.Vals[0])
				skill.ShowValue = hurtLine - cardGame.Monster.HurtSum
				if skill.ShowValue < 0 {
					skill.ShowValue = 0
				}
			} else {
				// 当前回合已经触发过反击
				skill.ShowValue = 0
			}
		case data.BSCardMonsterSkillEnum.Shild: // 14.护盾
			skill.ShowValue = cardGame.Monster.Shield
		case data.BSCardMonsterSkillEnum.Hp_decrease: // 15.龙人的酒
			skill.ShowValue = 0
		case data.BSCardMonsterSkillEnum.Injuried_recover: // 16.恢复，治愈
			skill.ShowValue = 0
		case data.BSCardMonsterSkillEnum.Hp_subPoint_dmgAccumulation: // 17.激怒
			skill.ShowValue = 0
		case data.BSCardMonsterSkillEnum.Attack_percent_dmgUp: // 18.暴击
			skill.ShowValue = 0
		case data.BSCardMonsterSkillEnum.Dmg_percent_block: // 19.闪避
			skill.ShowValue = 0
		case data.BSCardMonsterSkillEnum.Shield_firstTurn: // 20.首回合护甲
			skill.ShowValue = 0
		case data.BSCardMonsterSkillEnum.Shield_fightBack: // 21.护甲>0,反伤
			skill.ShowValue = int64(skillT.Vals[0])
		case data.BSCardMonsterSkillEnum.Buff_clear: // 22.净化
			skill.ShowValue = skill.Cd
		case data.BSCardMonsterSkillEnum.BeSpAtk_hurtPercentUp: // 23.属性攻击倍数增伤
			if skill.StayRound >= 99 {
				skill.ShowValue = skill.Val
			} else {
				skill.ShowValue = skill.StayRound
			}
		case data.BSCardMonsterSkillEnum.BeSpAtk_hurtPointUp: // 24.属性攻击点数增伤
			if skill.StayRound >= 99 {
				skill.ShowValue = skill.Val
			} else {
				skill.ShowValue = skill.StayRound
			}
		}
	}
}

// 获取卡牌伤害
func getCardHurt_BSGame(cardHurt data.CardHurtInfo, monsterRace int64, cardRaceTarget int64) (hurtVal int64, hurtValSupport int64, hurtInfoKey int64) {
	hurtInfoKey = int64(cardHurt.HurtInfo.Key)
	hurtValSupport = 0
	if int64(cardHurt.HurtTyp) == data.BSCardHurtTypeEnum.RaceHeal || int64(cardHurt.HurtTyp) == data.BSCardHurtTypeEnum.RaceHurt {
		if monsterRace != cardRaceTarget {
			hurtVal = 0
			return
		}
	}
	switch cardHurt.HurtInfo.Key {
	case 1: // 固定伤害
		hurtVal = int64(cardHurt.HurtInfo.Val1)
	case 2: // 范围伤害
		hurtVal = utils.RandomInt64(int64(cardHurt.HurtInfo.Val1), int64(cardHurt.HurtInfo.Val2))
	case 3: // 权重，概率，伤害
		if utils.RandomInt64(1, 100) <= int64(cardHurt.HurtInfo.Val1) {
			hurtVal = int64(cardHurt.HurtInfo.Val2)
		} else {
			hurtVal = 0
		}
	case 5: // 双数值填充
		hurtVal = int64(cardHurt.HurtInfo.Val1)
		hurtValSupport = int64(cardHurt.HurtInfo.Val2)
	}
	return
}

// 世界boss，玩家回血处理
func BloodReturn(from string, us *m.User, cardGame *m.BSGame) (uProp *m.UpdateProp, err error) {
	if cardGame.ShopState == 0 {
		err = errors.NewErrcode(data.Errcode.ServerErr, fmt.Sprintf("神秘商店没有开启=%d", cardGame.ShopState))
		log.WithFields(log.Fields{
			"cardGame.ShopState": cardGame.ShopState,
		}).Error("神秘商店没有开启")
		return
	}

	tpl, ok := data.Get("BossSlotShops", uint64(cardGame.ShopBuyCnt+1))
	if !ok {
		err = errors.NewErrcode(data.Errcode.ConfigNotFound, fmt.Sprintf("没有找到BossSlotShops配表，或没有该id=%d", cardGame.ShopBuyCnt+1))
		log.WithFields(log.Fields{
			"cardGame.ShopBuyCnt+1": cardGame.ShopBuyCnt + 1,
		}).Error("读取BossSlotShops配表失败")
		return
	}
	tplT := tpl.(data.BossSlotShop)
	// 消耗钻石
	uProp, err = Cost(from, us, []m.BaseKV{{Key: data.GlobalEnum.Diamond, Val: int64(tplT.CostDiam)}})
	if err != nil {
		return
	}
	// 消耗钻石成功，给玩家回血
	cardGame.HP += int64(tplT.BloodReturn) * cardGame.MaxHP / 100
	// 血量超过最大值，直接赋予最大值。相当于，直接回满血。
	if cardGame.HP > cardGame.MaxHP {
		cardGame.HP = cardGame.MaxHP
	}
	// 增加次数
	cardGame.ShopBuyCnt++
	cardGame.Update(cardGame)
	return
}

// 检测世界boss 商店状态
func BossSlotCheckShop(cardGame *m.BSGame) int64 {
	// 商店开启状态，不做处理
	if cardGame.ShopState == 1 {
		return 0
	}
	// 商店没有开启，检查玩家血量是否低于20%
	val := 100 * cardGame.HP / cardGame.MaxHP
	if val >= 20 {
		return 0
	}
	// 血量低于20%，开启商店
	cardGame.ShopState = 1
	cardGame.Update(cardGame)
	return 1
}

// 世界boss，清除玩家自己的战斗信息
func BossSlotClean(us *m.User) {
	cardGame := &m.BSGame{
		Uid: us.Uid,
	}
	cardGame.Update(cardGame)
}
